{"record":{"id":"bb9a1e33a6357569","repo":"gastownhall/beads","slug":"failed-to-acquire-connection-w","errorCode":null,"errorMessage":"failed to acquire connection: %w","messagePattern":"failed to acquire connection: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dolt/store.go","lineNumber":3043,"sourceCode":"\n// commitWorkingSet stages the dirty tables reported by dolt_status and commits\n// them with '-m'. The config table is staged according to mode: configExclude\n// skips it (GH#2455) so a concurrent writer's half-applied issue_prefix change\n// is never swept into an unrelated commit; configIncludeUserKVOnly stages it for\n// the pre-pull path but refuses when any non-kv. (internal) config key is dirty;\n// configIncludeAll stages every dirty config row to conclude an explicit merge\n// resolution.\nfunc (s *DoltStore) commitWorkingSet(ctx context.Context, message string, mode configCommitMode) (retErr error) {\n\tctx, span := doltTracer.Start(ctx, \"dolt.commit\",\n\t\ttrace.WithSpanKind(trace.SpanKindClient),\n\t\ttrace.WithAttributes(s.doltSpanAttrs()...),\n\t)\n\tdefer func() { endSpan(span, retErr) }()\n\n\t// Pin a single connection so all operations run on the same Dolt session.\n\tconn, err := s.db.Conn(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to acquire connection: %w\", err)\n\t}\n\tdefer conn.Close()\n\n\t// GH#2455: stage each dirty table individually, skipping config unless the\n\t// mode opts it in, to avoid sweeping up stale issue_prefix changes from\n\t// concurrent operations. Exclude dolt_ignore'd tables (wisps, wisp_%, leases)\n\t// with the same anti-join HasCommittablePending uses: they surface in\n\t// dolt_status but are never stageable, and the fail-hard DOLT_ADD loop below\n\t// must see only tables it can actually stage. A dirty wisp or lease row is the\n\t// normal steady state; staging it depends on Dolt's version-specific\n\t// ignored-table DOLT_ADD behavior (a silent no-op on 2.2.0), so filtering here\n\t// keeps ordinary commits from failing whenever an ignored table is dirty.\n\trows, err := conn.QueryContext(ctx, `\n\t\tSELECT s.table_name FROM dolt_status s\n\t\tWHERE NOT EXISTS (\n\t\t\tSELECT 1 FROM dolt_ignore di\n\t\t\tWHERE di.ignored = 1\n\t\t\tAND s.table_name LIKE di.pattern","sourceCodeStart":3025,"sourceCodeEnd":3061,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dolt/store.go#L3025-L3061","documentation":"This is the pinned-connection acquisition failure in the auto-commit/commit working-set path, which pins a single connection so staging (DOLT_ADD), committing (DOLT_COMMIT), and session-scoped queries all run in one Dolt session. This error means the commit could not even begin because db.Conn(ctx) failed. Nothing was staged or committed, so repo state is unchanged.","triggerScenarios":"Any commit flow (e.g. pre-pull auto-commit) when the pool has no available connection before the context deadline, the context is canceled, or the driver fails to establish/return a session.","commonSituations":"Several concurrent bd operations each pinning connections; an interrupted sync leaving contexts canceled; embedded Dolt hitting max connections under heavy CLI concurrency.","solutions":["Read the wrapped driver error to identify pool timeout vs cancellation vs connectivity.","Check for connection leaks in other DoltStore methods (every db.Conn must be closed) that starve the pool.","Serialize heavyweight operations or increase SetMaxOpenConns so a pinned session is available.","Retry the commit once the pool/context issue is resolved; commitWorkingSet is safe to retry before staging began."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// before commit paths\nif err := ctx.Err(); err != nil { return err }\n// ensure a single-writer discipline around bd operations","typeGuard":null,"tryCatchPattern":"err := store.Commit(ctx, msg)\nif err != nil {\n\tif errors.Is(err, context.DeadlineExceeded) { /* retry with fresh ctx */ }\n\treturn fmt.Errorf(\"commit: %w\", err)\n}","preventionTips":["Use a fresh, adequately-timeouted context for commit operations.","Serialize writes; avoid many concurrent bd processes on one repo.","Watch for connection leaks in custom code using UnderlyingDB().","Keep the Dolt engine running/healthy before sync operations."],"tags":["go","database","connection-pool","commit"],"backgroundTag":"db-connection-acquire-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}