{"record":{"id":"08bf8ea330b0f71c","repo":"googleapis/mcp-toolbox","slug":"failed-to-connect-to-cockroachdb-after-d-retries","errorCode":null,"errorMessage":"failed to connect to CockroachDB after %d retries: %w","messagePattern":"failed to connect to CockroachDB after (.+?) retries: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cockroachdb/cockroachdb.go","lineNumber":516,"sourceCode":"\n\tvar pool *pgxpool.Pool\n\tfor attempt := 0; attempt <= maxRetries; attempt++ {\n\t\tpool, err = pgxpool.New(ctx, connURL.String())\n\t\tif err == nil {\n\t\t\terr = pool.Ping(ctx)\n\t\t}\n\n\t\tif err == nil {\n\t\t\treturn pool, nil\n\t\t}\n\n\t\tif attempt < maxRetries {\n\t\t\tbackoff := baseDelay * time.Duration(math.Pow(2, float64(attempt)))\n\t\t\ttime.Sleep(backoff)\n\t\t}\n\t}\n\n\treturn nil, fmt.Errorf(\"failed to connect to CockroachDB after %d retries: %w\", maxRetries, err)\n}\n\nfunc ConvertParamMapToRawQuery(queryParams map[string]string) string {\n\tvalues := url.Values{}\n\tfor k, v := range queryParams {\n\t\tvalues.Add(k, v)\n\t}\n\treturn values.Encode()\n}\n","sourceCodeStart":498,"sourceCodeEnd":526,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cockroachdb/cockroachdb.go#L498-L526","documentation":"This error is returned by initCockroachDBConnectionPoolWithRetry when the toolbox fails to establish a connection pool to CockroachDB after exhausting maxRetries attempts with exponential backoff (baseDelay * 2^attempt). The wrapped error (%w) is the last underlying connection failure, typically a dial timeout, bad DSN, or unreachable host. It surfaces during source Initialize, so the server cannot start the CockroachDB source.","triggerScenarios":"Calling Initialize on the CockroachDB source when every pooled connection attempt fails: wrong host/port in the connection config, network/firewall blocking the cluster, invalid credentials, or the CockroachDB cluster being down. The retry loop sleeps backoff = baseDelay * 2^attempt between attempts and returns this error only after the final attempt.","commonSituations":"Typo in the CockroachDB connection string or port (default 26257), cluster paused/deleted in CockroachCloud, VPC/firewall rules blocking egress, DNS resolution failures, TLS certificate misconfiguration, or a briefly unavailable cluster during maintenance that outlasts the retry window.","solutions":["Verify the CockroachDB host, port, database, and credentials in the source config and test them with cockroach sql or psql (CockroachDB is wire-compatible)","Check network reachability: ping/curl the cluster host and confirm firewall/VPC rules allow outbound TCP to port 26257","Confirm the cluster is running (CockroachCloud console) and not in maintenance; if it is transient, simply restarting the toolbox after the cluster recovers resolves it","If using TLS, verify certificate paths and CA trust; try sslmode=disable locally to isolate TLS issues"],"exampleFix":"// before (config)\nkind: source\nname: crdb-src\ntype: cockroachdb\nhost: crdb-internal.example.com // unreachable internal host\nport: \"26257\"\n// after\nkind: source\nname: crdb-src\ntype: cockroachdb\nhost: your-cluster.g8.cockroachlabs.cloud\nport: \"26257\"","handlingStrategy":"validation","validationCode":"// Before starting the toolbox, verify CockroachDB connectivity\npackage main\n\nimport (\n\t\"context\"\n\t\"database/sql\"\n\t\"fmt\"\n\t\"time\"\n\n\t_ \"github.com/jackc/pgx/v5/stdlib\"\n)\n\nfunc checkCockroach(dsn string) error {\n\tctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)\n\tdefer cancel()\n\tdb, err := sql.Open(\"pgx\", dsn)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer db.Close()\n\treturn db.PingContext(ctx)\n}\n\nfunc main() {\n\tif err := checkCockroach(\"postgresql://user:pass@host:26257/defaultdb?sslmode=verify-full\"); err != nil {\n\t\tpanic(fmt.Sprintf(\"CockroachDB unreachable: %v\", err))\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Test the DSN with cockroach sql or psql before configuring the source","Monitor cluster health and keep maintenance windows outside toolbox restarts","Use the CockroachCloud public connection path unless networking is verified","Validate TLS certs and sslmode early in deployment"],"tags":["cockroachdb","connection","retry","database"],"backgroundTag":"connection-retry-exhausted","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}