Skip to content

unexpected end of JSON input error when trying to register driver #1010

@bunyk

Description

@bunyk

Bug Description

Hello! I'm trying to connect to Google cloudsql Mariadb database using worload identity federation from AWS. Here is the code I run:

func connectWithProxy(conf config.GCPDB) (*sqlx.DB, error) {
	if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
		// just a check to make sure credentials.DetectDefault will detect correct file
		return nil, fmt.Errorf("GOOGLE_APPLICATION_CREDENTIALS environment variable not set")
	}

	creds, err := credentials.DetectDefault(&credentials.DetectOptions{
		Scopes: []string{storage.CloudPlatformScope},
	})
	if err != nil {
		return nil, errl.Source(err)
	}

	if _, err := mysql.RegisterDriver("cloudsql-mysql", cloudsqlconn.WithCredentials(creds)); err != nil {
		return nil, errl.Source(err)
	}
	dbConn := fmt.Sprintf(
		"%s:%s@cloudsql-mysql(%s)/%s?parseTime=true",
		conf.User, conf.Password, conf.Host, conf.Name,
	)
	db, err := sql.Open(
		"cloudsql-mysql",
		dbConn,
	)
	if err != nil {
		return nil, errl.Source(err)
	}
	return sqlx.NewDb(db, "mysql"), nil
}

But it gives me error failed to get instance: refresh error: failed to get instance metadata (connection name = "ccs-wfm:europe-west3:ccs-wfm"): Get "https://sqladmin.googleapis.com/sql/v1beta4/projects/ccs-wfm/instances/ccs-wfm/connectSettings?alt=json&prettyPrint=false\": unexpected end of JSON input

Example code (or command)

Stacktrace

Steps to reproduce?

  1. ?
  2. ?
  3. ?
    ...

Environment

  1. OS type and version: alpine-3.12:latest
  2. Go version: 1.24.4
  3. Cloud SQL Go Connector version: v1.18.1

Additional Details

No response

Metadata

Metadata

Assignees

Labels

type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions