{"record":{"id":"8aa8aca18cc11d71","repo":"gastownhall/beads","slug":"rebuild-pool-after-migration-w","errorCode":null,"errorMessage":"rebuild pool after migration: %w","messagePattern":"rebuild pool after migration: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dolt/store.go","lineNumber":2771,"sourceCode":"}\n\n// rebuildPoolAfterMigration replaces the main connection pool (s.db) after a\n// migrating open. Migrations run over a separate one-off pool\n// (openMigrationDB); a connection already pooled in s.db before migrations\n// ran (e.g. the startup Ping in newServerMode) stays pinned to the\n// pre-migration Dolt session root, so the first read through it returns 0\n// rows / table-not-found and does not self-heal on retry (be-itm5). A\n// non-migrating open (applied == 0 — the common re-open-of-an-\n// already-migrated-database path) has no stale state to fix and must return\n// before touching s.db or dialing anything.\nfunc (s *DoltStore) rebuildPoolAfterMigration(ctx context.Context, applied int) error {\n\tif applied == 0 {\n\t\treturn nil\n\t}\n\n\tnewDB, err := sql.Open(\"mysql\", s.connStr)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"rebuild pool after migration: %w\", err)\n\t}\n\tapplyPoolLimits(newDB, s.cfg)\n\n\tif err := newDB.PingContext(ctx); err != nil {\n\t\t_ = newDB.Close()\n\t\treturn fmt.Errorf(\"rebuild pool after migration: %w\", err)\n\t}\n\n\told := s.db\n\ts.db = newDB\n\treturn old.Close()\n}\n\n// IsClosed returns true if the store has been closed.\nfunc (s *DoltStore) IsClosed() bool {\n\treturn s.closed.Load()\n}\n","sourceCodeStart":2753,"sourceCodeEnd":2789,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dolt/store.go#L2753-L2789","documentation":"After a migration applied changes, rebuildPoolAfterMigration opens a fresh connection pool with sql.Open using the store's connection string; this error wraps that open failing. As with sql.Open generally, it usually means driver/DSN-level problems rather than server availability (ping failures produce the sibling error at line 2777).","triggerScenarios":"rebuildPoolAfterMigration invoked with applied>0 migrations, and sql.Open(\"mysql\", s.connStr) errors because the mysql driver is not registered or s.connStr is invalid in a way that survives sql.Open validation (empty string, corrupt).","commonSituations":"connStr mutated to empty/invalid during runtime reconfiguration; driver not linked into binary; tests constructing DoltStore by hand with a bogus connStr then triggering a migration path.","solutions":["Validate s.connStr is a well-formed DSN before constructing the store (mysql.ParseDSN in a startup check)","Ensure the mysql driver import is present in the binary","If seen in tests, construct DoltStore with a real ParseDSN-validated connection string"],"exampleFix":"// before\nif _, err := sql.Open(\"mysql\", s.connStr); err != nil { ... }\n// after\nif _, err := mysql.ParseDSN(s.connStr); err != nil {\n    return fmt.Errorf(\"invalid connStr: %w\", err)\n}\nnewDB, err := sql.Open(\"mysql\", s.connStr)","handlingStrategy":"validation","validationCode":"// validate connStr before pool rebuild\nif _, err := mysql.ParseDSN(s.connStr); err != nil {\n    return fmt.Errorf(\"cannot rebuild pool, bad connStr: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Go: driver-registration failures are permanent; surface at startup\nnewDB, err := sql.Open(\"mysql\", s.connStr)\nif err != nil {\n    // do not retry: missing driver / invalid DSN is a build/config bug\n    return fmt.Errorf(\"rebuild pool after migration: %w\", err)\n}","preventionTips":["Parse the DSN once at store construction and reuse the parsed cfg","Keep the mysql driver import in the main binary","Use a real DSN (never empty string) in test store construction"],"tags":["go","mysql","connection-pool","configuration"],"backgroundTag":"sql-driver-not-registered","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}