{"record":{"id":"5b454c4a2c610031","repo":"gastownhall/beads","slug":"failed-to-acquire-ignored-tx-connection-w","errorCode":null,"errorMessage":"failed to acquire ignored tx connection: %w","messagePattern":"failed to acquire ignored tx connection: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dolt/transaction.go","lineNumber":330,"sourceCode":"\t\t// A stale pooled connection or a session on another branch: a fresh\n\t\t// dial always worked before, so discard this one (its session state is\n\t\t// untouched) and fall through to the fallback.\n\t\t_ = conn.Close()\n\t}\n\n\t// Fallback: a dedicated single-connection pool, paying the fresh dial the\n\t// borrow path exists to avoid.\n\tdoltMetrics.ignoredTxFreshPool.Add(ctx, 1)\n\tdb, err := sql.Open(\"mysql\", s.connStr)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to open ignored tx connection: %w\", err)\n\t}\n\tdb.SetMaxOpenConns(1)\n\n\tconn, err := db.Conn(ctx)\n\tif err != nil {\n\t\t_ = db.Close()\n\t\treturn nil, nil, fmt.Errorf(\"failed to acquire ignored tx connection: %w\", err)\n\t}\n\n\ttx, err = beginTxOnConn(ctx, conn, branch)\n\tif err != nil {\n\t\t_ = conn.Close()\n\t\t_ = db.Close()\n\t\treturn nil, nil, err\n\t}\n\n\treturn func() { _ = conn.Close(); _ = db.Close() }, tx, nil\n}\n\n// borrowConnForIgnoredTx returns a second connection borrowed from the main pool\n// for the ignored-tables transaction, or nil if borrowing is unsafe or would\n// block. The caller falls back to a dedicated single-connection pool on nil.\nfunc (s *DoltStore) borrowConnForIgnoredTx(ctx context.Context) *sql.Conn {\n\tst := s.db.Stats()\n\t// MaxOpenConns==1: the caller already pinned the pool's only connection for","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dolt/transaction.go#L312-L348","documentation":"On the fresh-dial fallback path, db.Conn(ctx) must dial the Dolt SQL server for the dedicated ignored-tables connection. This error wraps that acquisition failure — dial error, auth failure, TLS mismatch, or ctx timeout/cancellation while connecting. The intermediate pool is closed before returning, so no resource leaks beyond the failed dial.","triggerScenarios":"Dolt server unreachable (down, wrong host/port, firewall) at fallback time; wrong credentials or missing TLS config in s.connStr; ctx canceled/expired during the fresh dial; server at max-connection limit.","commonSituations":"Pool exhausted AND the network is degraded (borrow skipped, fresh dial also fails); credentials rotated; embedded Dolt server not started; IPv6/localhost resolution differences for the DSN host.","solutions":["Verify the Dolt server is up and reachable (nc/curl the host:port, or `mysql` client connect)","Check credentials and TLS settings in the DSN","Check ctx deadlines — a fresh dial needs the full handshake time; widen the timeout","Note the borrow fast path already failed: pool exhaustion plus dial failure usually means server/network trouble, fix that root cause"],"exampleFix":"// before\nctx, cancel := context.WithTimeout(ctx, 50*time.Millisecond) // too short for a fresh handshake\n// after\nctx, cancel := context.WithTimeout(ctx, 5*time.Second)","handlingStrategy":"retry","validationCode":"if err := db.PingContext(ctx); err != nil { return fmt.Errorf(\"dolt server unreachable: %w\", err) }","typeGuard":null,"tryCatchPattern":"if err != nil && (errors.Is(err, context.DeadlineExceeded) || isDialErr(err)) {\n    return retryWithBackoff(ctx, op) // dial failures are safe to retry pre-callback\n}","preventionTips":["Health-check the Dolt server before write-heavy operations","Provision credentials/TLS correctly and test with a mysql client","Allow several seconds for fresh-dial handshakes in ctx deadlines","Watch server max-connection limits if many processes dial concurrently"],"tags":["go","dolt","connection","network"],"backgroundTag":"db-connection-acquisition-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}