-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Always call callbacks in outgoing streams #2240
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,13 @@ var numRequests = 20; | |
var done = 0; | ||
|
||
var server = http.createServer(function(req, res) { | ||
res.end('ok'); | ||
|
||
res.end('ok', common.mustCall(function() {})); | ||
|
||
// We *might* get a socket already closed error here, which | ||
// occurs when the socket was destroyed before we finished | ||
// writing our data. | ||
res.on('error', function() {}); | ||
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. Then lets check the error here, just to be sure. 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. But should that error cause the test to fail? I don't believe this particular fail means what the test was created to test has failed. 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. As it is we simply ignore everything right? As the comment says, if we check if the error is actually socket closed error, wouldn't it be better? 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. oh I see what you're saying. good point. yes, checking for expected errors, but still throwing on unexpected errors, would be a smart thing to do. |
||
|
||
// Oh no! The connection died! | ||
req.socket.destroy(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is a strange hybrid between err-back and event emitter.
/cc @nodejs/tsc Feedback on basically emitting the error twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One or the other seems better. Maybe
if (typeof callback === 'function') callback(err); else self.emit('error', err);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this had been discussed some time back. See nodejs/node-v0.x-archive#7477 where this change originated from.
IMHO it should only be one or the other, like @cjihrig says. If a callback is supplied, then pass the error and not emit. Otherwise emit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Down with double errors!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that solution. @laino mind making that change?