{"record":{"id":"23c43d3c9088b889","repo":"gastownhall/beads","slug":"flush-failed-to-list-databases-w","errorCode":null,"errorMessage":"flush: failed to list databases: %w","messagePattern":"flush: failed to list databases: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/doltserver/doltserver.go","lineNumber":1588,"sourceCode":"\t\tPort: port,\n\t\tUser: \"root\",\n\t}.String()\n\tdb, err := sql.Open(\"mysql\", dsn)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"flush: failed to open connection: %w\", err)\n\t}\n\tdefer db.Close()\n\tdb.SetMaxOpenConns(1)\n\tdb.SetConnMaxLifetime(10 * time.Second)\n\n\tif err := db.PingContext(ctx); err != nil {\n\t\treturn fmt.Errorf(\"flush: server not reachable: %w\", err)\n\t}\n\n\t// List all databases, skipping system databases\n\trows, err := db.QueryContext(ctx, \"SHOW DATABASES\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"flush: failed to list databases: %w\", err)\n\t}\n\tvar databases []string\n\tfor rows.Next() {\n\t\tvar name string\n\t\tif err := rows.Scan(&name); err != nil {\n\t\t\tcontinue\n\t\t}\n\t\t// Skip Dolt system databases\n\t\tif name == \"information_schema\" || name == \"mysql\" || name == \"performance_schema\" {\n\t\t\tcontinue\n\t\t}\n\t\tdatabases = append(databases, name)\n\t}\n\t_ = rows.Close()\n\n\tif len(databases) == 0 {\n\t\treturn nil\n\t}","sourceCodeStart":1570,"sourceCodeEnd":1606,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/doltserver/doltserver.go#L1570-L1606","documentation":"FlushWorkingSet wraps a failure of the 'SHOW DATABASES' query with this message after a successful ping, meaning the connection dropped or the server rejected the query mid-flush. The caller treats the whole flush as failed (best-effort; the stop proceeds with a warning), so uncommitted working-set changes may be lost for that shutdown.","triggerScenarios":"db.QueryContext(ctx, \"SHOW DATABASES\") errors after the ping succeeded: the connection died between ping and query (server restart/crash in that window), the server killed the connection (max connections, idle timeout misconfig), or Dolt returned an engine error enumerating databases.","commonSituations":"Server being concurrently restarted by another bd process during shutdown; connection-limit exhaustion on a shared server; flaky network to a remote shared server; Dolt version-specific errors on SHOW DATABASES.","solutions":["Retry bd dolt stop — the error is often transient if the server was mid-restart","Confirm only one bd process is managing the server (avoid concurrent stop/start from other terminals or CI jobs)","Check the dolt server log for engine errors or connection kills at the failure time","If on a remote server, verify network stability (a dropped connection between ping and query produces exactly this error)","As a fallback, run explicit dolt commits (cd <data-dir> && dolt add -A && dolt commit -m 'manual flush') to protect uncommitted work"],"exampleFix":"// before: concurrent stop/start kills the flush connection\n// $ (terminal A) bd dolt stop &  (terminal B) bd dolt restart\n// after: serialize server lifecycle operations\n// $ bd dolt restart   # single command handles flush + stop + start","handlingStrategy":"retry","validationCode":"// Sanity-check the connection is still usable before the flush queries\nconn, err := net.DialTimeout(\"tcp\", net.JoinHostPort(host, strconv.Itoa(port)), 2*time.Second)\nif err != nil {\n    return fmt.Errorf(\"server unreachable on %s:%d; aborting flush\", host, port)\n}\nconn.Close()","typeGuard":null,"tryCatchPattern":"err := doltserver.FlushWorkingSet(host, port)\nif err != nil && strings.Contains(err.Error(), \"failed to list databases\") {\n    // transient drop (restart/limits): one retry, then log and continue best-effort\n    time.Sleep(time.Second)\n    if err := doltserver.FlushWorkingSet(host, port); err != nil {\n        log.Printf(\"warning: flush failed after retry: %v\", err)\n    }\n}","preventionTips":["Serialize all server lifecycle operations through a single bd process","Raise server connection limits on shared multi-user servers","Check the dolt server log for engine errors on SHOW DATABASES","Keep server and client dolt versions compatible","Commit explicitly before shutdowns on unstable networks"],"tags":["go","mysql","sql","flush","connection-drop"],"backgroundTag":"query-connection-failure","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}