gastownhall/beads · error
failed to ping server: %w
Error message
failed to ping server: %w
What it means
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.
Source
Thrown at cmd/bd/doctor/perf_dolt.go:146
TLS: tls,
}.String()
// Measure connection time
start := time.Now()
db, err := sql.Open("mysql", dsn)
if err != nil {
return fmt.Errorf("failed to open MySQL connection: %w", err)
}
defer db.Close()
// Set connection pool settings
db.SetMaxOpenConns(5)
db.SetMaxIdleConns(2)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := db.PingContext(ctx); err != nil {
return fmt.Errorf("failed to ping server: %w", err)
}
metrics.ConnectionTime = time.Since(start).Milliseconds()
// Run all diagnostics
return runDoltDiagnosticQueries(ctx, db, metrics)
}
// runDoltDiagnosticQueries runs the diagnostic queries and populates metrics
func runDoltDiagnosticQueries(ctx context.Context, db *sql.DB, metrics *DoltPerfMetrics) error {
// Get issue counts
if err := db.QueryRowContext(ctx, "SELECT COUNT(*) FROM issues").Scan(&metrics.TotalIssues); err != nil {
return fmt.Errorf("failed to count issues: %w", err)
}
if err := db.QueryRowContext(ctx, "SELECT COUNT(*) FROM issues WHERE status != 'closed'").Scan(&metrics.OpenIssues); err != nil {
metrics.OpenIssues = -1 // Mark as unavailable
}
View on GitHub (pinned to 71377f2769)
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
Example fix
// before
ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
// after
if !serverReachable(host, port) { startDoltServer() }
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) Defensive patterns
Strategy: retry
Validate before calling
conn, err := net.DialTimeout("tcp", addr, 2*time.Second); if err != nil { /* server down — start it */ } Try / catch
if err != nil && strings.Contains(err.Error(), "failed to ping server") {
// inspect driver error: refused vs access denied vs timeout
var mysqlErr *mysql.MySQLError
if errors.As(errors.Unwrap(err), &mysqlErr) { /* handle by code */ }
} Prevention
- Pre-flight TCP reachability check before pinging
- Ensure credentials match dolt sql-server config
- Set realistic timeouts for loaded servers
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- server not reachable: %w
- dolt server connection failed: %w
- dolt sql-server is not running on %s:%d; start it with 'bd d
- failed to open MySQL connection: %w
- ensure global db: server not reachable: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/04642966691e0ddc.
Report an issue: GitHub.