stream: fix early drain after Utf8Stream reopen - #65633
Open
mcollina wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
ShogunPanda
approved these changes
Aug 29, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65633 +/- ##
=======================================
Coverage 90.05% 90.05%
=======================================
Files 754 754
Lines 255722 255724 +2
Branches 48314 48310 -4
=======================================
+ Hits 230281 230286 +5
- Misses 16555 16560 +5
+ Partials 8886 8878 -8
🚀 New features to boost your workflow:
|
ronag
approved these changes
Aug 29, 2026
If a 'ready' listener starts a write after reopen(), the reopen path still emits 'drain' from a nextTick before that write completes, so a listener reading the file on 'drain' can observe it empty. This is the race behind the test-fastutf8stream-reopen flake deflaked on the test side in 2e8a4b1. Skip the extra emit when a write is in flight: #release() emits the real 'drain' once the write completes, so no event is lost. The regression test defers the reopened file's fs.write by one setImmediate, deterministically landing the write after the nextTick on which the premature 'drain' used to fire. Refs: nodejs@2e8a4b1a8ce Signed-off-by: Matteo Collina <hello@matteocollina.com>
mcollina
force-pushed
the
fix-utf8stream-reopen-drain
branch
from
August 29, 2026 08:40
7837e2f to
90dfd42
Compare
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.
If a
'ready'listener starts a write afterreopen(), the reopen path still emits'drain'from anextTickbefore that write completes, so a listener reading the file on'drain'can observe it empty. This is the underlying race behind thetest-fastutf8stream-reopenflake that 2e8a4b1 deflaked on the test side ("The reopen path also emits a 'drain' of its own from a nextTick before the write has landed") — this fixes the library so'drain'is never emitted whilestream.writing === true.Skip the extra emit when a write is in flight:
#release()emits the real'drain'once the write completes, so no event is lost.The regression test defers the reopened file's
fs.writeby onesetImmediate, which deterministically lands the write after thenextTickon which the premature'drain'used to fire. It fails without the lib change (assertswriting === falseon'drain'; observedtrue, file empty) and passes with it.Verified with 800 runs of the test under 16× parallel CPU contention: 0 failures (28/800 before the fix, reproducing the CI signature exactly).
Same fix submitted to upstream sonic-boom: pinojs/sonic-boom#255.