Skip to content

fix(database_writer_pool): add exponential backoff retry for RPC time… - #317

Merged
godamongstmen897 merged 2 commits into
Goldii-locks:mainfrom
benedictworks-home:fix/303-database-writer-pool-backoff
Aug 30, 2026
Merged

fix(database_writer_pool): add exponential backoff retry for RPC time…#317
godamongstmen897 merged 2 commits into
Goldii-locks:mainfrom
benedictworks-home:fix/303-database-writer-pool-backoff

Conversation

@benedictworks-home

Copy link
Copy Markdown
Contributor

Summary
Files Changed
Source File: database-writer-pool.ts

Added WriteResult.rpcRetries field to track RPC-level retries separately from DB-conflict retries
Added WriterPoolRpcRetryConfig interface (matches the naming/shape of RpcRetryConfig in rpc-poller-client.ts)
Added module-level config with getters, setters, and reset:
setWriterPoolRpcRetryConfig(partial)
getWriterPoolRpcRetryConfig()
resetWriterPoolRpcRetryConfig()
Added isRpcTimeoutError(err) — case-insensitive pattern match against RPC connection error patterns
Added computeRpcBackoffMs(attempt, config) — pure function computing initialBackoffMs * multiplier^attempt capped at maxBackoffMs
Refactored execution flow into two layers:
Inner executeWriteWithDbRetry() — existing SQLite locked/busy retry (unchanged behavior)
Outer executeWrite() — new RPC timeout exponential-backoff wrapper that only retries on matched timeout patterns and propagates all other errors immediately
Test File: database-writer-pool.test.ts

Added imports for 7 new exported helpers
Added computeRpcBackoffMs suite (5 tests): initial value, exponential increase, max cap, custom multiplier, custom initial+max
Added isRpcTimeoutError suite (3 tests): all 11 retryable patterns match, non-timeout errors don't match, non-Error values rejected
Added WriterPoolRpcRetryConfig suite (4 tests): defaults, partial overrides, defensive copy, reset restores defaults
Added queueWrite – RPC connection timeout retry integration suite (7 tests): first-attempt success, repeated timeout + exponential delay, max-attempts halt with correct error surfaced, successful recovery within limit, constraint-violation not retried, syntax-error not retried, rpcRetries present on both success and failure paths
Retry Strategy Parameters (Defaults)
Parameter Default Purpose
maxRetries 5 Max RPC retry attempts after the initial failure (total invocations = 1 + maxRetries)
initialBackoffMs 1000 Delay before first retry (attempt 0)
backoffMultiplier 2 Each retry delay multiplies by this factor (1s → 2s → 4s → 8s → …)
maxBackoffMs 30 000 Upper ceiling so growth cannot exceed 30 s
Formula: delay = min(initialBackoffMs * backoffMultiplier ^ attempt, maxBackoffMs)

Note: No jitter was added, consistent with all existing retry logic in this repository (rpc-poller-client, failover-recovery, webhooks/deliver). All four parameters are fully configurable at runtime via setWriterPoolRpcRetryConfig({ … }).

Retryable error patterns (case-insensitive substring match): timeout, ECONNRESET, ECONNREFUSED, ETIMEDOUT, socket hang up, network, status 429, status 503, status 502, request timeout, connect timeout — identical to the set used in rpc-poller-client.ts.

Verification
Typecheck: npx tsc --noEmit → exit 0, no errors
Build: npm run build (tsconfig.build.json) → exit 0, succeeds
Targeted tests: 41/41 pass in database-writer-pool.test.ts (34 existing + 7 new)
Full suite: 47/47 suites, 774/774 tests pass (22.5 s)
IDE diagnostics: 0 issues reported

Implements retry logic with exponentially increasing delay and a configurable max attempt cap for RPC connection timeout errors in database_writer_pool. Non-timeout errors are not retried.

Adds tests validating retry frequency growth up to max attempts.

Closes #303

…outs

Implements retry logic with exponentially increasing delay and a
configurable max attempt cap for RPC connection timeout errors in
database_writer_pool. Non-timeout errors are not retried.

Adds tests validating retry frequency growth up to max attempts.

Closes Goldii-locks#303
@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

@benedictworks-home Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@godamongstmen897
godamongstmen897 merged commit 70f897b into Goldii-locks:main Aug 30, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build exponential backoff retry strategies on database_writer_pool

2 participants