fix(rethink): attach connection error handler so a dropped connection doesn't crash the process#1000
Open
JohnMcLear wants to merge 1 commit into
Open
fix(rethink): attach connection error handler so a dropped connection doesn't crash the process#1000JohnMcLear wants to merge 1 commit into
JohnMcLear wants to merge 1 commit into
Conversation
… doesn't crash the process The rethinkdb Connection is an EventEmitter that re-emits raw socket errors (idle drop, server restart, failover, a proxy closing the connection) as an 'error' event. With no listener Node treats it as uncaught and terminates the host process. The rethink driver never attached one. This is the rethink analogue of the postgres bug in ether/etherpad#7878. This driver holds a single connection and does not auto-reconnect, so the fix is crash-prevention only: a dropped connection is logged instead of taking down the application (subsequent queries fail until re-init). - Attach `connection.on('error', …)` right after connect. - Add test/rethink/connection-drop.spec.ts: warm the connection, destroy the underlying socket (as a failover / proxy idle-timeout would), and assert the process survives and the handler logged it. Verified locally that this FAILS without the handler ("Uncaught Exception: simulated network drop") and PASSES with it. - rethink is not in the container test matrix, so run it via a dedicated `rethink-resilience` CI job (mirrors the postgres one). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Review Summary by Qodo(Agentic_describe updated until commit d56a8af)Prevent RethinkDB connection errors from crashing process
WalkthroughsDescription• Attach error handler to RethinkDB connection to prevent process crash • Handler logs dropped connections instead of terminating application • Add behavioral test simulating network drop and verifying survival • Add dedicated CI job for RethinkDB resilience testing Diagramflowchart LR
A["RethinkDB Connection"] -->|"raw socket error"| B["'error' event emitted"]
B -->|"without handler"| C["Uncaught exception"]
C -->|"Node behavior"| D["Process crash"]
B -->|"with handler"| E["Error logged"]
E -->|"application survives"| F["Graceful degradation"]
File Changes1. databases/rethink_db.ts
|
Code Review by Qodo
1. Test leaves connection open
|
Comment on lines
+59
to
+78
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 10.33.0 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 24 | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Connection-drop survival test | ||
| run: pnpm exec vitest run test/rethink/connection-drop.spec.ts |
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.
Problem
The rethink analogue of ether/etherpad#7878 (postgres, #998) and the redis case (#999). The rethinkdb
Connectionis an EventEmitter that re-emits raw socket errors — idle drop, server restart, failover, or a proxy/firewall closing the connection — as an'error'event (rethinkdb/net.js:this.rawSocket.on('error', err => this.emit('error', err))). With no listener, Node treats it as an uncaught exception and terminates the host process.rethink_db.tsattached none.Fix
Attach
connection.on('error', …)immediately after connect. This driver holds a single connection and does not auto-reconnect, so the fix is crash-prevention only: a dropped connection is logged instead of taking down Etherpad (subsequent queries fail until re-init). Reconnection would be a larger, separate change.Test (real, not a wiring assertion)
test/rethink/connection-drop.spec.tsstarts a rethinkdb container, warms the connection, then destroys the underlying socket — exactly what a failover / proxy idle-timeout surfaces to the client — and asserts the process survives and the handler logged it.Verified locally that without the handler the test fails with
Uncaught Exception: Error: simulated network drop, and passes with it. rethink isn't in the containertestmatrix, so it runs via a dedicatedrethink-resilienceCI job (mirrors the postgres one in #998).Verification
pnpm run lint/format:check/ts-check/build— cleanvitest run test/rethink/connection-drop.spec.ts— passes with fix, fails (uncaught) withoutAudit context (per-driver sweep from #998)
All ueberDB network backends were checked for this "missing error handler → crash on idle/dropped connection" class. One PR per affected driver:
PoolConnectionself-registers an'error'listener; verified by source + a behavioural test (no async pool error, no crash).MongoClientattachesthis.on('error', noop)in its constructor.error).🤖 Generated with Claude Code