fix(database_writer_pool): add exponential backoff retry for RPC time… - #317
Merged
godamongstmen897 merged 2 commits intoAug 30, 2026
Conversation
…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
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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