{"record":{"id":"3b34916fe0b6b4ba","repo":"gastownhall/beads","slug":"flush-failed-to-open-connection-w","errorCode":null,"errorMessage":"flush: failed to open connection: %w","messagePattern":"flush: failed to open connection: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/doltserver/doltserver.go","lineNumber":1575,"sourceCode":"\treturn nil\n}\n\n// FlushWorkingSet connects to the running Dolt server and commits any uncommitted\n// working set changes across all databases. This prevents data loss when the server\n// is about to be stopped or restarted. Returns nil if there's nothing to flush or\n// if the server is not reachable (best-effort).\nfunc FlushWorkingSet(host string, port int) error {\n\tctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)\n\tdefer cancel()\n\n\tdsn := doltutil.ServerDSN{\n\t\tHost: host,\n\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 {","sourceCodeStart":1557,"sourceCodeEnd":1593,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/doltserver/doltserver.go#L1557-L1593","documentation":"FlushWorkingSet wraps sql.Open(\"mysql\", dsn) failure with this message when preparing its best-effort connection (as root, no password) to the running dolt server before shutdown. As with all sql.Open errors, this indicates a malformed DSN or unregistered driver, not an unreachable server — the ping step handles reachability separately. The function is best-effort: callers only log a warning if it fails.","triggerScenarios":"sql.Open(\"mysql\", dsn) errors while building the root/no-password DSN from host and port — invalid characters in the configured host, or the mysql driver missing from the binary.","commonSituations":"A hand-edited config leaving stray characters in dolt.host; custom builds without the go-sql-driver/mysql import; automated tooling injecting malformed host values.","solutions":["Inspect the wrapped error for 'invalid DSN' and correct the host value in bd config (alphanumeric hostname or IP only)","Validate BEADS_DB_HOST / dolt.shared-server-host has no stray quotes, spaces, or scheme (no 'http://')","If building a custom binary, ensure _ \"github.com/go-sql-driver/mysql\" is imported","This is best-effort (uncommitted working-set changes may be lost); if it persists, commit work manually before bd dolt stop","Retry the stop/restart — the failure may come from transient config reload"],"exampleFix":"// before: scheme in host corrupts the DSN\n// host := \"http://127.0.0.1\"\n// after: plain host only\nhost := \"127.0.0.1\"","handlingStrategy":"validation","validationCode":"// Validate host is a clean hostname/IP before FlushWorkingSet builds its DSN\nif net.ParseIP(host) == nil {\n    if _, err := net.LookupHost(host); err != nil {\n        return fmt.Errorf(\"configured dolt host %q is not a valid host\", host)\n    }\n}\nif strings.ContainsAny(host, \"@:/() \\t\") {\n    return fmt.Errorf(\"configured dolt host %q contains invalid DSN characters\", host)\n}","typeGuard":null,"tryCatchPattern":"if err := doltserver.FlushWorkingSet(host, port); err != nil {\n    // best-effort by design: log and continue shutdown, but flag possible data loss\n    log.Printf(\"warning: working-set flush skipped (%v); uncommitted changes may remain\", err)\n}","preventionTips":["Keep dolt.host a plain hostname or IP — no schemes or DSN metacharacters","Never hand-edit bd config fields without validating afterwards","Import go-sql-driver/mysql in custom builds","Remember the flush is best-effort: commit critical work explicitly before bd dolt stop"],"tags":["go","mysql","dsn","flush","best-effort"],"backgroundTag":"invalid-dsn","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}