fix(client): swallow synchronous EPIPE from writeAfterFIN (#3282)#3283
Open
nkaradzhov wants to merge 2 commits into
Open
fix(client): swallow synchronous EPIPE from writeAfterFIN (#3282)#3283nkaradzhov wants to merge 2 commits into
nkaradzhov wants to merge 2 commits into
Conversation
net.Socket.write can throw synchronously with code 'EPIPE' on a half-closed socket, before the 'close' event fires. The throw escaped RedisSocket.write from a setImmediate flush and crashed the process. Preflight `writable`, wrap the cork/write loop in try/finally so uncork always runs, and narrowly swallow EPIPE — the close handler will reject the pending command via #waitingForReply. Fixes redis#3282 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace `any` casts with `unknown` and rename the unused `err` parameter to `_err` so `lint:changed` passes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
net.Socket.write can throw synchronously with code 'EPIPE' on a half-closed socket, before the 'close' event fires. The throw escaped RedisSocket.write from a setImmediate flush and crashed the process. Preflight
writable, wrap the cork/write loop in try/finally so uncork always runs, and narrowly swallow EPIPE — the close handler will reject the pending command via #waitingForReply.Fixes #3282
Description
Checklist
npm testpass with this change (including linting)?Note
Medium Risk
Touches core socket write-path behavior; while narrowly scoped and covered by new tests, it could change how some edge-case disconnect/write failures are handled during reconnects.
Overview
Prevents process crashes when
net.Socket.writethrows synchronously on half-closed connections by skipping writes when the underlying socket is not writable, wrapping the corked write loop intry/finallyto alwaysuncork(), and swallowing onlyEPIPEwhile rethrowing other errors.Adds targeted unit tests that capture the underlying
net.Socketto verify the new short-circuit behavior,EPIPEswallowing, and non-EPIPEerror propagation.Reviewed by Cursor Bugbot for commit e9d7f00. Bugbot is set up for automated code reviews on this repo. Configure here.