stream: fix Writable.toWeb() hang on synchronous drain · nodejs/node@dc57173 · GitHub
Skip to content

Commit dc57173

Browse files
Han5991sxa
authored andcommitted
stream: fix Writable.toWeb() hang on synchronous drain
A race condition in the Writable.toWeb() adapter caused the stream to hang if the underlying Node.js Writable emitted a 'drain' event synchronously during a write() call. This often happened when highWaterMark was set to 0. By checking writableNeedDrain immediately after a backpressured write, the adapter now correctly detects if the stream has already drained, resolving the backpressure promise instead of waiting indefinitely for an event that has already occurred. Fixes: #61145 Signed-off-by: sangwook <rewq5991@gmail.com> PR-URL: #61197 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c20aa4c commit dc57173

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/internal/webstreams/adapters.js

Lines changed: 3 additions & 0 deletions

test/parallel/test-whatwg-webstreams-adapters-to-writablestream.js

Lines changed: 23 additions & 0 deletions

0 commit comments

Comments
 (0)