GoogleCloudPlatform / GoogleCloudPlatform/cloud-sql-go-connector

unexpected end of JSON input error when trying to register driver

Open
#1,010 4 comments 0 reactions 1 assignee Claimed by @hessjcg View on GitHub
type: bug
Dominant language
Go
Stars
145
Forks
35
Avg merge
3d 22h
Merged PRs (30d)
5

Description

### 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:

```go
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)

```Go

```

### Stacktrace

```bash

```

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.