Repository navigation
Regression: socket hang up when uploading and streaming with pipeline #32184
Description
Activity
- changed the title
[-]Regression: socket hang up when uploading with custom headers[/-][+]Regression: socket hang up when uploading and streaming with pipeline[/+]on Mar 10, 2020 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
pipelinecall succeeds. The file is actually written, but there seems to be side effect on the http socket.- addedstreamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
on Mar 11, 2020 Yea, there is an unfortunate coupling between the req and res objects... should probably be decoupled when the req object
'finish'es, but that's semver major.I'll try to prepare 13.x fix later today.
Reacted by Anna Henningsen, Ruben Bridgewater and Szymon Marczak@ronag I thought that the
IncomingMessagepipeline fix was tagged as a major change (which I strongly disagree with the choice).@ronag I thought that the IncomingMessage pipeline fix was tagged as a major change (which I strongly disagree with the choice).
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
IncomingMessage.#32153 will set
socket = nullwhich is a potentially breaking change for code that assumes that socket is not null. They do not do the same thing (even if they solve the same problem for you).Reacted by Szymon MarczakI 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.
Reacted by Szymon MarczakOk, I get it now, thanks. Keep up the good work!
Reacted by Robert Nagy- added a commit that references this issue
on Mar 12, 2020 - added a commit that references this issue
on Jul 27, 2026
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.0and higher: