-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Regression: socket hang up when uploading and streaming with pipeline #32184
Comments
TL;DR; Client receive "socket hang up" error when reaching this middleware: const Koa = require("koa");
const fs = require("fs");
const util = require("util");
const stream = require("stream");
const app = new Koa();
const pipeline = util.promisify(stream.pipeline);
app.use(async ctx => {
const { "content-length": length } = ctx.request.headers;
const openFlags = fs.constants.O_WRONLY | fs.constants.O_CREAT;
const ws = fs.createWriteStream("test.bin", {
flags: openFlags,
encoding: "binary"
});
/*
!!! commenting the following line disable the "socket hang up" error !!!
*/
await pipeline(ctx.req, ws);
ctx.status = 200;
ctx.response.body = {
length: parseInt(length)
};
});
module.exports = app; |
Quite hard to debug, because the |
Yea, there is an unfortunate coupling between the req and res objects... should probably be decoupled when the req object I'll try to prepare 13.x fix later today. |
This comment has been minimized.
This comment has been minimized.
http1 objects are coupled with their corresponding res/req and cannot be treated independently as normal streams. Add a special exception for this in the pipeline cleanup. Fixes: nodejs#32184
@ronag I thought that the |
Sorry, I'm confused? You link to two different PR's there. |
This solution does the same as #32153 because you don't call the destroyer if the stream is an |
#32153 will set |
I was just working on backporting the other one #32212 (actually the same minute you commented). Maybe that's why I got confused by your comment. |
Ok, I get it now, thanks. Keep up the good work! |
http1 objects are coupled with their corresponding res/req and cannot be treated independently as normal streams. Add a special exception for this in the pipeline cleanup. Fixes: nodejs#32184 Backport-PR-URL: nodejs#32212
http1 objects are coupled with their corresponding res/req and cannot be treated independently as normal streams. Add a special exception for this in the pipeline cleanup. Fixes: #32184 Backport-PR-URL: #32212 PR-URL: #32197 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Everytime
What is the expected behavior?
With node
v13.9.0
:What do you see instead?
With node
v13.10.0
and higher:The text was updated successfully, but these errors were encountered: