Skip to content
← All reviews
remix-run/react-router #15324 · brophdawg11 · 4mo ago

Prevent streaming disconnects from crashing Node

Needs attention1 finding · openOpen the pull request on GitHub ↗
Panel verdict

The panel surfaced issues that deserve attention before merge.

1
raised by reviewers
1
kept by the panel

Findings

HighCorrectnessconfidence 0.95

destroyWritable may silently swallow legitimate writable errors

The destroyWritable function attaches a no-op once('error') listener before calling writable.destroy(error). This listener consumes the asynchronous 'error' event that Node emits when destroy() is called with an error on a writable that is not yet destroyed. However, if the writable is already destroyed (the early return on line 61-63), the function returns without attaching the error listener. In that case, if writable.destroy(error) was called elsewhere (or the writable was destroyed by some other mechanism) and the error event fires asynchronously, there is no listener to catch it, potentially crashing the process. The early return should also attach a no-op error listener to the already-destroyed writable to ensure any pending error events are consumed.

Suggested fix ·

function destroyWritable(writable: Writable, error: Error) { if (writable.destroyed) { // Ensure any pending error events from a previous destroy are consumed writable.once("error", () => {}); return; }

// The write promise carries this error to the caller. Also consume the // asynchronous error event from destroy so it cannot crash the process // after the writable error monitor has been cleaned up. writable.once("error", () => {}); writable.destroy(error); }

3 reviewers · deepseek/deepseek-v4-flash · reviewed in 24s · 3 files, +46 −2

Ship the PR.
Skip the noise.

Free on 2 repositories · No credit card · Advisory only—never blocks a merge