gastownhall/beads · error
acquire connection for compact: %w
Error message
acquire connection for compact: %w
What it means
DoltStore.Compact pins one pooled connection because the versioncontrolops.Compact implementation runs session-scoped DOLT_ stored procedures. This error wraps a failure to acquire that connection from the pool, so the squash of old Dolt commits never starts. The real cause (timeout, canceled context, pool exhaustion) is wrapped via %w.
Source
Thrown at internal/storage/dolt/store.go:2922
// Flatten squashes all Dolt commit history into a single commit.
// Pins a single connection because the stored procedures (DOLT_CHECKOUT,
// DOLT_RESET, etc.) rely on session-scoped state that would be lost if
// steps execute on different pooled connections.
func (s *DoltStore) Flatten(ctx context.Context) error {
conn, err := s.db.Conn(ctx)
if err != nil {
return fmt.Errorf("acquire connection for flatten: %w", err)
}
defer conn.Close()
return versioncontrolops.Flatten(ctx, conn)
}
// Compact squashes old Dolt commits while preserving recent ones.
// Pins a single connection for session-scoped stored procedures.
func (s *DoltStore) Compact(ctx context.Context, initialHash, boundaryHash string, oldCommits int, recentHashes []string) error {
conn, err := s.db.Conn(ctx)
if err != nil {
return fmt.Errorf("acquire connection for compact: %w", err)
}
defer conn.Close()
return versioncontrolops.Compact(ctx, conn, initialHash, boundaryHash, oldCommits, recentHashes)
}
// UnderlyingDB returns the underlying *sql.DB connection
func (s *DoltStore) UnderlyingDB() *sql.DB {
return s.db
}
// =============================================================================
// Version Control Operations (Dolt-specific extensions)
// =============================================================================
func (s *DoltStore) commitAuthorString() string {
return fmt.Sprintf("%s <%s>", s.committerName, s.committerEmail)
}
View on GitHub (pinned to 71377f2769)
Solutions
- Inspect the wrapped error chain to distinguish pool exhaustion from context cancellation from driver failure.
- Ensure all pinned-connection users (Flatten/Compact/commit paths) close connections promptly; leaks exhaust the pool and surface here.
- Re-run Compact with a longer context timeout and during a quieter window of concurrent activity.
- Confirm database connectivity and credentials if the wrapped error indicates the server is unreachable.
Defensive patterns
Strategy: retry
Validate before calling
// before calling Compact
if err := ctx.Err(); err != nil { return err }
stats := db.Stats()
if stats.MaxOpenConnections > 0 && stats.InUse >= stats.MaxOpenConnections { /* wait or back off */ } Try / catch
err := store.Compact(ctx, init, boundary, old, recent)
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
// reschedule with longer timeout
} Prevention
- Schedule compaction with generous timeouts and low concurrency.
- Close all pinned connections promptly to keep pool headroom.
- Monitor sql.DBStats for pool saturation.
- Retry compaction after transient driver errors rather than failing the whole job.
When it happens
Trigger: Calling DoltStore.Compact when db.Conn(ctx) returns an error: no free connection in the pool within the context deadline, context canceled, or driver-level connection failure.
Common situations: Compacting history while many other operations hold pinned sessions; a background compaction job scheduled with a too-short timeout; CI environments where the Dolt process was torn down between steps.
Related errors
- acquire connection for gc: %w
- acquire connection for remote-ref prune: %w
- acquire connection for flatten: %w
- failed to acquire connection: %w
- ErrTransaction
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/c2b1ebe3386887ad.
Report an issue: GitHub.