{"record":{"id":"04642966691e0ddc","repo":"gastownhall/beads","slug":"failed-to-ping-server-w","errorCode":null,"errorMessage":"failed to ping server: %w","messagePattern":"failed to ping server: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/perf_dolt.go","lineNumber":146,"sourceCode":"\t\tTLS:      tls,\n\t}.String()\n\n\t// Measure connection time\n\tstart := time.Now()\n\tdb, err := sql.Open(\"mysql\", dsn)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open MySQL connection: %w\", err)\n\t}\n\tdefer db.Close()\n\n\t// Set connection pool settings\n\tdb.SetMaxOpenConns(5)\n\tdb.SetMaxIdleConns(2)\n\n\tctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\n\tdefer cancel()\n\tif err := db.PingContext(ctx); err != nil {\n\t\treturn fmt.Errorf(\"failed to ping server: %w\", err)\n\t}\n\tmetrics.ConnectionTime = time.Since(start).Milliseconds()\n\n\t// Run all diagnostics\n\treturn runDoltDiagnosticQueries(ctx, db, metrics)\n}\n\n// runDoltDiagnosticQueries runs the diagnostic queries and populates metrics\nfunc runDoltDiagnosticQueries(ctx context.Context, db *sql.DB, metrics *DoltPerfMetrics) error {\n\t// Get issue counts\n\tif err := db.QueryRowContext(ctx, \"SELECT COUNT(*) FROM issues\").Scan(&metrics.TotalIssues); err != nil {\n\t\treturn fmt.Errorf(\"failed to count issues: %w\", err)\n\t}\n\n\tif err := db.QueryRowContext(ctx, \"SELECT COUNT(*) FROM issues WHERE status != 'closed'\").Scan(&metrics.OpenIssues); err != nil {\n\t\tmetrics.OpenIssues = -1 // Mark as unavailable\n\t}\n","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/perf_dolt.go#L128-L164","documentation":"After opening the connection, runDoltServerDiagnostics pings the Dolt SQL server with a 30-second timeout (db.PingContext). Failure to establish/verify a live connection is wrapped with this message and the underlying driver error.","triggerScenarios":"db.PingContext(ctx) fails: server not listening on host:port (connection refused), auth rejected, TLS mismatch, or the 30s timeout expires on a hung/overloaded server.","commonSituations":"dolt sql-server stopped between the running-check and connect; wrong credentials in DSN; firewall/Docker networking blocking the port; server overloaded so handshake exceeds 30s.","solutions":["Confirm dolt sql-server is running and reachable (nc -zv host port)","Fix credentials/DSN if the driver reports access denied","Increase timeout or check server load/logs if the 30s context deadline is exceeded"],"exampleFix":"// before\nctx, _ := context.WithTimeout(context.Background(), 30*time.Second)\n// after\nif !serverReachable(host, port) { startDoltServer() }\nctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)","handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", addr, 2*time.Second); if err != nil { /* server down — start it */ }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to ping server\") {\n    // inspect driver error: refused vs access denied vs timeout\n    var mysqlErr *mysql.MySQLError\n    if errors.As(errors.Unwrap(err), &mysqlErr) { /* handle by code */ }\n}","preventionTips":["Pre-flight TCP reachability check before pinging","Ensure credentials match dolt sql-server config","Set realistic timeouts for loaded servers"],"tags":["beads","dolt","mysql","ping","network"],"backgroundTag":"connection-refused","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}