-
Notifications
You must be signed in to change notification settings - Fork 278
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
π Bug Report β Runtime APIs: piping ReadableStream
to an IdentityTransformStream
results in uncaught TypeError: This WritableStream has been closed.
#992
Comments
I am getting the same here after the return of the new Response
|
Ditto on the I think the issue might be broader than the title suggests... in my case I'm just piping a ReadableStream through a CompressionStream (no IdentityTransformStream involved), along these lines: const eventStream = someReadableStream
.pipeThrough(new TextEncoderStream())
.pipeThrough(new CompressionStream('gzip')); // the error goes away if compression stream is not included This is during local dev with |
This problem has also been reported to me in zip.js. Here's a complete example below to reproduce the issue with the export default {
async fetch() {
const { readable, writable } = new CompressionStream("deflate-raw");
const helloWorldStream = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode("Hello, World!"));
controller.close();
}
});
helloWorldStream.pipeTo(writable);
return new Response(readable, {
headers: {
"Content-Disposition": 'attachment; filename="file.raw"',
"Content-Type": "application/octet-stream",
"Cache-Control": "no-cache",
}
});
}
}; It can be circumvented with a fake globalThis.CompressionStream = class {
constructor(format) {
const compressionStream = new CompressionStream(format);
const writer = compressionStream.writable.getWriter();
return new TransformStream({
async transform(chunk) {
await writer.write(chunk);
},
async flush() {
await writer.close();
}
});
}
};
// App code below
// ... |
I ran into the same issue and async function pipeThrough(r: ReadableStream, w: WritableStream) {
const writer = w.getWriter()
for await (const chunk of r) {
writer.write(chunk)
}
writer.close()
}
const { readable, writable } = new TransformStream<string, string>()
const compressor = new CompressionStream('gzip')
const pipe = readable
.pipeThrough(new TextEncoderStream())
pipeThrough(pipe, compressor.writable) // replacement for .pipeThrough(new CompressionStream('gzip')) |
Hey! π With the following
workerd
configuration......and running
workerd serve config.capnp --verbose
, logsUncaught (in promise); exception = TypeError: This WritableStream has been closed.
on request.Finding the error string and adding
KJ_DBG
s to all those places shows the error is coming from:workerd/src/workerd/api/streams/internal.c++
Line 814 in 9f56120
Replacing
const readable = new ReadableStream(...);
with......also leads to the same error.
Replacing
new IdentityTransformStream()
withnew TransformStream()
fixes the issue.The text was updated successfully, but these errors were encountered: