Repository navigation
stream: close Utf8Stream fd after pending write - #67355
Merged
nodejs-github-bot merged 1 commit intoNov 14, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67355 +/- ##
=======================================
Coverage 90.69% 90.70%
=======================================
Files 801 801
Lines 281875 281932 +57
Branches 54317 54324 +7
=======================================
+ Hits 255652 255715 +63
+ Misses 16348 16346 -2
+ Partials 9875 9871 -4
🚀 New features to boost your workflow:
|
destroy() fsynced and closed the fd right away, even while an fs.write() on it was still running on the thread pool. The write then failed with EBADF, emitted as an 'error' that crashed the process when nothing listened for it, or landed in whatever file reused the fd number. Close the fd once the in-flight write completes, as fs.WriteStream does. Data buffered behind it is still dropped, so 'finish' is not emitted in that case. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
christianaurichzm
force-pushed
the
deflake-periodicflush
branch
from
November 13, 2026 00:26
36322b3 to
1d3c5a8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Member
Author
|
@mcollina could you take a look when you get a chance? sonic-boom's cc @nodejs/streams |
This comment was marked as outdated.
This comment was marked as outdated.
jasnell
approved these changes
Nov 14, 2026
Collaborator
Collaborator
Collaborator
|
Landed in 7996b18 |
aduh95
pushed a commit
that referenced
this pull request
Nov 19, 2026
destroy() fsynced and closed the fd right away, even while an fs.write() on it was still running on the thread pool. The write then failed with EBADF, emitted as an 'error' that crashed the process when nothing listened for it, or landed in whatever file reused the fd number. Close the fd once the in-flight write completes, as fs.WriteStream does. Data buffered behind it is still dropped, so 'finish' is not emitted in that case. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com> PR-URL: #67355 Refs: https://github.com/nodejs/reliability/blob/main/reports/2026-11-09.md Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.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.
Utf8Stream#destroy()closes the fd while anfs.write()on it may still be running on the thread pool. The write then fails withEBADF, which crashes the process if nothing listens for'error', or lands in whatever file reuses the fd number.test-fastutf8stream-periodicflushhit theEBADFcase in CI.a.logstays empty andb.loggets the line.destroy()now closes the fd once the in-flight write completes, asfs.WriteStreamdoes. A write that hitsEAGAINarounddestroy(), either already waiting on the retry timer or coming back withEAGAINafterwards, is still retried on the closed fd, as on main. So is the rest of a partial write whendestroy()is called from a'write'listener. I'd fix those separately.With every
fs.write()delayed by 50 ms,test-fastutf8stream-periodicflushfails 50/50 on main and passes with this change. An earlier version of this PR only changed the test.Refs: https://github.com/nodejs/reliability/blob/main/reports/2026-11-09.md