You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stream.finished is failing to detect a closed ServerResponse in the case the request is aborted (response emits close but doesn't emit finish).
This is happening when stream.finished is called with an already closed ServerResponse. I thought it should work in this case because if I give a destroyed PassThrough stream for example it works properly - it executes the callback.
conststream=require("stream");constpass=newstream.PassThrough();pass.on("close",()=>{stream.finished(pass,(err)=>{// it worksconsole.log("stream.finished worked",err);});});pass.destroy();
Now in the case of a response the callback isn't executed:
conststream=require("stream");consthttp=require("http");http.createServer((req,res)=>{res.on("finish",()=>{// res will not be finishedconsole.log("response finished")});res.on("close",()=>{// res will be closedconsole.log("response closed");stream.finished(res,(err)=>{// but this callback will not be executedconsole.log("stream.finished worked");});});res.statusCode=200;res.setHeader("Content-Type","text/plain");res.write("Hello world");}).listen(3000,"localhost",()=>{console.log(`Server running at http://localhost:3000/`);constreq=http.get("http://localhost:3000",(res)=>{console.log("Request was made");setTimeout(()=>req.abort(),100);});});
What is the expected behavior?
I expected console output to be:
Server running at http://localhost:3000/
Request was made
response closed
stream.finished worked
What do you see instead?
The output is:
Server running at http://localhost:3000/
Request was made
response closed
The text was updated successfully, but these errors were encountered:
finished should invoke callback on closed OutgoingMessage the
same way as for regular streams.
Fixes: #34301
PR-URL: #34313Fixes: #34274
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
What steps will reproduce the bug?
stream.finished
is failing to detect a closedServerResponse
in the case the request is aborted (response emitsclose
but doesn't emitfinish
).This is happening when
stream.finished
is called with an already closedServerResponse
. I thought it should work in this case because if I give a destroyedPassThrough
stream for example it works properly - it executes the callback.Now in the case of a response the callback isn't executed:
What is the expected behavior?
I expected console output to be:
What do you see instead?
The output is:
The text was updated successfully, but these errors were encountered: