-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Always call callbacks in outgoing streams #2240
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 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() {}); | ||
|
||
|
|
||
| // 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?