stream: fix early drain after Utf8Stream reopen · nodejs/node@dfe0617 · GitHub
Skip to content

Commit dfe0617

Browse files
mcollinaaduh95
authored andcommitted
stream: fix early drain after Utf8Stream reopen
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: 2e8a4b1a8ce Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #65633 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e260fd1 commit dfe0617

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎lib/internal/streams/fast-utf8-stream.js‎

Lines changed: 3 additions & 1 deletion

‎test/parallel/test-fastutf8stream-reopen.js‎

Lines changed: 42 additions & 0 deletions

0 commit comments

Comments
 (0)