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
Feat: Added response.destroy method #1675
Conversation
Calls destroy() on the socket that received the IncomingMessage. If error is provided, an 'error' event is emitted and error is passed as an argument to any listeners on the event.
Thanks for digging into this! 💯 A couple follow-up thoughts:
This is a bit curious given the description in the documentation. Does
Regarding this piece of code – I'm not sure – is it relevant to |
I'm not sure either, but might be the part that raise the
I really don't know, from what I see in the http_client.js core file look it won't.. but I didn't test it without, I mostly looked at the implementation of Also maybe we should check for the socket existence before calling the destroy method to avoid calling on an already destroyed socket as said in the description (I cutted out) from the first file:
|
Fix the failing lint tests
I don't think overriding the The bit that's lacking is our Socket surrogate class. Comparing the current implementation vs the docs, shows that it doesn't handle being passed an error correctly.
Lines 57 to 60 in 4d0fbbf
If you're curious what Node does normally, the Updating the destroy(err) {
this.destroyed = true
this.readable = this.writable = false
if (err) {
this.emit('error', err)
}
return this
} The one other thing that would need to change would be to update this line so that Line 114 in 4d0fbbf
This is where the propagation happens in Node. It probably doesn't make sense to add the other missing events at this time. Wait to see if there is an actual need. With those two changes, the tests @b4dnewz wrote for this PR passed for me locally. |
I also initially had some doubt about it, your observations are good and a cleaner way to do it, I will update the code with your suggestions. |
This reverts commit b68e87b. This add suggested code to socket class on destroy method
if (err) { | ||
this.emit('error', err) | ||
} | ||
return 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.
Is return this
needed?
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.
That's the documented behavior.
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.
Ah, I see it now. Thanks.
🎉 This PR is included in version 11.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Calling `destroy` on the the response, with an error, not correctly propagates through the socket and then the request object. This aligns with Node's native functionality. Fixes: #1669
Calling `destroy` on the the response, with an error, not correctly propagates through the socket and then the request object. This aligns with Node's native functionality. Fixes: #1669
🎉 This PR is included in version 11.2.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
Calling `destroy` on the the response, with an error, not correctly propagates through the socket and then the request object. This aligns with Node's native functionality. Fixes: #1669
It adds the destroy method to the response to manually terminate a connection and optionally raise an error captured from listeners bound to request
error
event.As discussed in #1669
I'm still not sure if this is enough, I took a look at http_incoming from node http core:
And from http_client also from node http core:
And based on the description provided in the documentation:
It will raise the
error
event only if called with an actual Error instance.But since I'm not familiar with node http core lib I'm not sure if this will terminate the connection properly or is required to manually perform other tasks on the request object.