Repository navigation
eos and pipeline will deadlock if streams are not in assumed state #28650
Copy link
Copy link
Closed
Labels
streamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
Description
Activity
- changed the title
[-]eos and pipeline will deadlock if source is already closed [/-][+]eos and pipeline will deadlock if streams are not in valid state[/+]on Jul 12, 2019 - changed the title
[-]eos and pipeline will deadlock if streams are not in valid state[/-][+]eos and pipeline will deadlock if streams are not in assumed state[/+]on Jul 12, 2019 I would suggest that
eosbe updated to work similarly toon-finishedwhere the callback is invoked if the stream is already in a "complete" state.- addedstreamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
on Jul 12, 2019 This was fixed in a PR
👋 Hi, @ronag do you happen to remember the PR that was supposed to fix this issue? I think I'm encountering the same issue, for which I've created a minimal reproduction.
const { finished, PassThrough, pipeline } = require('stream'); const http = require('http'); const server = http.createServer((req, res) => { console.log('server: request received'); const body = new PassThrough().end('foo'); setTimeout(() => { console.log('server: pipeline begin'); return pipeline(body, res, (err) => { console.log('server: pipeline end'); if (err) { console.error('server: pipeline err:', err); } }); }, 100); }); server.listen({ host: '127.0.0.1', port: 0 }, (err) => { const addr = server.address(); const uri = `http://${addr.address}:${addr.port}`; const req = http.request(uri).end(); req.on('response', async (res) => { console.log('response received'); for await (const chunk of res) { console.log('client: body: ', chunk.toString()); } console.log('closing server'); server.close(() => { console.log('server closed'); }); }); finished(req, (err) => { console.log('client: end'); if (err) { console.error('client: error: ', err); } }); // aborted request will cause server pipeline to never complete setTimeout(() => req.abort(), 50); });
Without the
req.abort()call, the process with exit with output:client: end server: request received server: pipeline begin server: pipeline end response received client: body: foo closing server server closedWith the
req.abort()call, the process will not exit with output:client: end server: request received server: pipeline beginI get the same behavior on node versions 10, 12 and 13.
Is this the expected behavior? If so, can you point me in the right direction on how this should be handled on the server side?
cc @mcollina
It will be included in Node 14
Reacted by Jonathan Stewmon
Metadata
Metadata
Assignees
Labels
streamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
Currently,
pipelineandeosdoes not take into account whether the streams are "valid" or not to begin with.Consider this potentially common example:
or less common
This will fail... even though I believe it should error with a premature close (or something similar)?
Basically
eosandpipelinemakes assumptions of the arguments which are not enforced...