-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
stream: pipeline should use req.abort() to destroy response #31054
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
destroy(err) on http response will propagate the error to the request causing 'error' to be unexpectedly emitted. Furthermore, response.destroy() unlike request.abort() does not _dump buffered data. Fixes a breaking change introduced in 6480882. Prefer res.req.abort() over res.destroy() until this situation is clarified. Fixes: #31029 Refs: 6480882
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const { Stream, Writable, Readable, Transform, pipeline } = require('stream'); | ||
| const { | ||
| Stream, | ||
| Writable, | ||
| Readable, | ||
| Transform, | ||
| pipeline, | ||
| PassThrough | ||
| } = require('stream'); | ||
| const assert = require('assert'); | ||
| const http = require('http'); | ||
| const { promisify } = require('util'); | ||
|
|
@@ -483,3 +490,30 @@ const { promisify } = require('util'); | |
| { code: 'ERR_INVALID_CALLBACK' } | ||
| ); | ||
| } | ||
|
|
||
| { | ||
| const server = http.Server(function(req, res) { | ||
| res.write('asd'); | ||
| }); | ||
| server.listen(0, function() { | ||
| http.request({ | ||
| port: this.address().port, | ||
| path: '/', | ||
| method: 'GET' | ||
| }, (res) => { | ||
| const stream = new PassThrough(); | ||
|
|
||
| stream.on('error', common.mustCall()); | ||
|
|
||
| pipeline( | ||
| res, | ||
| stream, | ||
| common.mustCall((err) => { | ||
| server.close(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to also validate the error here?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. At least that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Unfortunately we get an unexpected/different error (
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't understand how this is related to #31060. AFAIK none of the It seems a regression on master to me const stream = require('stream');
const data = Buffer.alloc(1024);
{
const readable = new stream.Readable({
read() {
this.push(data);
}
});
const writable = new stream.Writable({
write(chunk, encoding, callback) {
callback();
}
});
writable.on('error', console.error);
readable.pipe(writable);
writable.destroy(new Error('Oops'));
}
{
const readable = new stream.Readable({
read() {
this.push(data);
}
});
const writable = new stream.Writable({
write(chunk, encoding, callback) {
callback();
}
});
stream.pipeline(readable, writable, console.error);
writable.destroy(new Error('Oops'));
}This prints on Node.js 13.5.0 and on Node.js master
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bisecting points to 67ed526.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. I’ll add it to the proposals list.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can this thread be resolved? We need a fix with the bug this PR aims to solve for node v13, or better revert the few commits that caused the problem in the first place.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this specific thread needs to be urgently resolved (or at the least it's a different issue). This PR in its current form resolves the original issue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, this discussion should not block the PR. The issue discussed here is caused by a semver-major change that will not be included in v13.x |
||
| }) | ||
| ); | ||
|
|
||
| stream.destroy(new Error('oh no')); | ||
| }).end().on('error', common.mustNotCall()); | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.