-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closing WritableStream from TransformStream causes Node.js process to crash #54453
Comments
Your original code threw an error for me:
But with some slight modifications, I was able to reproduce: import { TransformStream } from "node:stream/web";
const { writable } = new TransformStream();
(async () => {
try {
let writer = writable.getWriter();
await writer.write(" ");
writer.releaseLock();
writer = writable.getWriter();
await writer.close();
writer.releaseLock();
console.log("Done!");
} catch (err) {
console.error("Error:", err);
}
})(); $ node repro.async.mjs && echo "Exit code: $?"
Exit code: 0 Compared to other streams: const stream = new WritableStream();
try {
let writer = stream.getWriter();
await writer.write(" ");
writer.releaseLock();
writer = stream.getWriter();
await writer.close();
writer.releaseLock();
console.log("Done!");
} catch (err) {
console.error("Error:", err);
} $ node repro.async.mjs && echo "Exit code: $?"
Done!
Exit code: 0 |
IIUC The issue has to do with import { TransformStream } from "node:stream/web";
await (new TransformStream()).writable.getWriter().write(" ");
|
With your example I also experience a crash and no output in my terminal. Edit: The exit code also shows as 0 |
Yes, it's the write blocking entire thread, not the close line With write call
import { TransformStream } from "node:stream/web";
const { writable } = new TransformStream();
(async () => {
try {
let writer = writable.getWriter();
await writer.write(" ");
console.log("Done!");
} catch (err) {
console.error("Error:", err);
}
})(); ./out/Release/node repros/54453.js && echo "Exit code $?"
Exit code 0 Without write call
import { TransformStream } from "node:stream/web";
const { writable } = new TransformStream();
(async () => {
try {
let writer = writable.getWriter();
// await writer.write(" ");
console.log("Done!");
} catch (err) {
console.error("Error:", err);
}
})(); ./out/Release/node repros/54453.js && echo "Exit code $?"
Done!
Exit code 0 |
I see what's going on here: you need to read to resolve write. import {
TransformStream,
} from 'node:stream/web';
const transform = new TransformStream();
await Promise.all([
transform.writable.getWriter().write('A'),
transform.readable.getReader().read(),
]);
console.log("Done!"); ./out/Release/node repros/54453.js && echo "Exit code $?"
Done!
Exit code 0 Without read: import {
TransformStream,
} from 'node:stream/web';
const transform = new TransformStream();
await Promise.all([
transform.writable.getWriter().write('A'),
// transform.readable.getReader().read(),
]);
console.log("Done!"); ./out/Release/node repros/54453.js && echo "Exit code $?"
Exit code 0 edit: |
@nodejs/v8 |
Version
v20.16.0
Platform
Subsystem
No response
What steps will reproduce the bug?
I ran this code and my Node.js process crashed with no output:
This causes a crash:
This doesn't:
How often does it reproduce? Is there a required condition?
If I close the
WritableStream
on theTransformStream
example without awaiting theclose()
promise then the process will proceed to logDone!
.What is the expected behavior? Why is that the expected behavior?
I figured the stream would close or throw some kind of error if it cannot.
What do you see instead?
The Node.js process crashes without any thrown errors and doesn't trigger the
beforeExit
orexit
process events.Additional information
I've simplified my code into the reproducible above, that's why I create multiple writers.
No response
The text was updated successfully, but these errors were encountered: