-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
http: emit 'aborted' event for ClientRequest #15270
Changes from 1 commit
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 |
---|---|---|
|
@@ -360,9 +360,10 @@ function socketCloseListener() { | |
// NOTE: It's important to get parser here, because it could be freed by | ||
// the `socketOnData`. | ||
var parser = socket.parser; | ||
req.emit('close'); | ||
|
||
if (req.res && req.res.readable) { | ||
// Socket closed before we emitted 'end' below. | ||
req.emit('aborted'); | ||
req.res.emit('aborted'); | ||
var res = req.res; | ||
res.on('end', function() { | ||
|
@@ -374,9 +375,12 @@ function socketCloseListener() { | |
// receive a response. The error needs to | ||
// fire on the request. | ||
req.socket._hadError = true; | ||
req.emit('aborted'); | ||
req.emit('error', createHangUpError()); | ||
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'm not 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. I think aborted should at least be emitted after error in case someone removes their error listener after aborted? Anyone else? 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'm 👎 in not emitting an error here. 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. @mcollina: aborted after or before error? 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. aborted after. 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 |
||
} | ||
|
||
req.emit('close'); | ||
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. Is this correct? I think new Promise((resolve, reject) => req.on('close', resolve).on('error', reject)) Where the error is ignored since the promise is already resolved through |
||
|
||
// Too bad. That output wasn't getting written. | ||
// This is pretty terrible that it doesn't raise an error. | ||
// Fixed better in v0.10 | ||
|
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.
Is this correct? This branch means there's a response coming but we haven't received its end. I don't think this qualifies for an 'aborted' event for the request (only the response).
If this is motivated by how this works in h2, it's slightly different there because you have the request & response in one (duplex stream), instead of separate like with http1.
Then again, maybe I'm severely overthinking this.
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.
Well, from an api user's perspective the response could conceptually be part of the request (think h2)?
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 both behaviours make sense. I would prefer the h2 way just to avoid confusion.