Repository navigation
.pipeTo(Writable.toWeb(process.stdout)) returns a never-settling Promise #56139
Description
Activity
- addedweb streamsIssues and PRs related to the Web Streams API.Issues and PRs related to the Web Streams API.
on Dec 5, 2024 Some (small followups):
Simplified to get rid of
Readable.toWebimport { Writable } from 'node:stream' import { ReadableStream } from 'node:stream/web' await ReadableStream.from(["test"]).pipeTo(Writable.toWeb(process.stdout))
node test.mjs testWarning: Detected unsettled top-level await at file:///workspace/test.mjs:4 await ReadableStream.from(["test"]).pipeTo(Writable.toWeb(process.stdout)) ^Without
Writable.toWebthere's no error:import { ReadableStream } from 'node:stream/web' await ReadableStream.from(["test"]).pipeTo(new WritableStream())
And just to make sure let's implement a naive implementation of a
WritableStreamimport { ReadableStream } from 'node:stream/web' import { setTimeout } from 'node:timers/promises' const streamWritable = process.stdout await ReadableStream.from(["test"]).pipeTo(new WritableStream({ write(chunk) { if (streamWritable.writableNeedDrain || !streamWritable.write(chunk)) { return new Promise(resolve => streamWritable.once('drain', resolve)) } }, close() { return setTimeout(1000) } }))
The problem is not that there's a warning, it's that the promise never resolves:
$ node -e ' const {Writable} = require("node:stream"); const {ReadableStream} = require("node:stream/web"); ReadableStream.from(["test\n"]).pipeTo(Writable.toWeb(process.stdout)).then(() => console.log("Done"), console.error)' test $ echo $? 0
As you can see, the
console.log("Done")is never reached. The warning is a mere consequence of awaiting a never-settling promise on the top-level scope.Reacted by Róbert Kiss- changed the title
[-]awaiting `.pipeTo(Writable.toWeb(process.stdout))` results in warning[/-][+]`.pipeTo(Writable.toWeb(process.stdout))` returns a never-settling Promise[/+]on Dec 5, 2024 The problem is not that there's a warning, it's that the promise never resolves:
Indeed. I had a few extra minutes to do some initial testing. I looks like when the code gets here
closedisundefinedwhich returns a promise here.I'm guessing
closedis supposed to be handled incleanupbut when I debug I never get there which leads me to suspect thateosis not running the suppliedcallbackfor some reason.So that was me not setting up my debugging env propperly, the
callbackis executed, so I'll have to dig some more.I decided to go in a slightly different direction and started testing with different node version, and it look like this works in
v21.7.3, but is broken inv22.0.0. Also tested in inv23.3.0where it's also broken.It could be related to a V8 update, or another semver-major commit of v22.x but I don't see any related
- Reacted by Antoine du Hamel and Mikael Karon
Oh well, I guess it's nice to have found something new rather than a regression 🤷
The issue persists in node 23.11.0
I found a workaround which prevents throwing
Warning: Detected unsettled top-level await.await ReadableStream.from(['test']).pipeTo(Writable.toWeb(process.stdout), { preventClose: true })github-actions commented
on Apr 26, 2026 on Apr 26, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Apr 26, 2026 github-actions commented
on May 26, 2026 on May 26, 2026 – with GitHub ActionsContributorMore actionsThis issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 240 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
Version
Platform
Subsystem
node:stream
What steps will reproduce the bug?
create file
test.mjsrun
How often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
no warning,
awaitto work as expectedWhat do you see instead?
warning about unsettled top-level await is shown
Additional information
No response