gastownhall/beads · error
failed to acquire connection: %w
Error message
failed to acquire connection: %w
What it means
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.
Source
Thrown at internal/storage/dolt/store.go:3043
// commitWorkingSet stages the dirty tables reported by dolt_status and commits
// them with '-m'. The config table is staged according to mode: configExclude
// skips it (GH#2455) so a concurrent writer's half-applied issue_prefix change
// is never swept into an unrelated commit; configIncludeUserKVOnly stages it for
// the pre-pull path but refuses when any non-kv. (internal) config key is dirty;
// configIncludeAll stages every dirty config row to conclude an explicit merge
// resolution.
func (s *DoltStore) commitWorkingSet(ctx context.Context, message string, mode configCommitMode) (retErr error) {
ctx, span := doltTracer.Start(ctx, "dolt.commit",
trace.WithSpanKind(trace.SpanKindClient),
trace.WithAttributes(s.doltSpanAttrs()...),
)
defer func() { endSpan(span, retErr) }()
// Pin a single connection so all operations run on the same Dolt session.
conn, err := s.db.Conn(ctx)
if err != nil {
return fmt.Errorf("failed to acquire connection: %w", err)
}
defer conn.Close()
// GH#2455: stage each dirty table individually, skipping config unless the
// mode opts it in, to avoid sweeping up stale issue_prefix changes from
// concurrent operations. Exclude dolt_ignore'd tables (wisps, wisp_%, leases)
// with the same anti-join HasCommittablePending uses: they surface in
// dolt_status but are never stageable, and the fail-hard DOLT_ADD loop below
// must see only tables it can actually stage. A dirty wisp or lease row is the
// normal steady state; staging it depends on Dolt's version-specific
// ignored-table DOLT_ADD behavior (a silent no-op on 2.2.0), so filtering here
// keeps ordinary commits from failing whenever an ignored table is dirty.
rows, err := conn.QueryContext(ctx, `
SELECT s.table_name FROM dolt_status s
WHERE NOT EXISTS (
SELECT 1 FROM dolt_ignore di
WHERE di.ignored = 1
AND s.table_name LIKE di.patternView on GitHub (pinned to 71377f2769)
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.
Defensive patterns
Strategy: retry
Validate before calling
// before commit paths
if err := ctx.Err(); err != nil { return err }
// ensure a single-writer discipline around bd operations Try / catch
err := store.Commit(ctx, msg)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) { /* retry with fresh ctx */ }
return fmt.Errorf("commit: %w", err)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Several concurrent bd operations each pinning connections; an interrupted sync leaving contexts canceled; embedded Dolt hitting max connections under heavy CLI concurrency.
Related errors
- failed to commit orphaned dependency removals: %w
- schema: pin connection: %w
- acquire connection for gc: %w
- acquire connection for remote-ref prune: %w
- acquire connection for flatten: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/bb9a1e33a6357569.
Report an issue: GitHub.