destroy request on error to avoid hanging sockets#1141
destroy request on error to avoid hanging sockets#1141benzekrimaha wants to merge 3 commits intodevelopment/1.3from
Conversation
On timeout or other errors the socket was left open; destroy the request so the socket is properly closed.
Hello benzekrimaha,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
Request integration branchesWaiting for integration branch creation to be requested by the user. To request integration branches, please comment on this pull request with the following command: Alternatively, the |
Issue: HD-4352
maeldonn
left a comment
There was a problem hiding this comment.
Could you add a test that reproduces the original problem (socket left open on error) and verifies it is now fixed?
Yeah if you are able to add a little test that counts connections or something it's nice, but might be hard I don't know |
| }).on('error', (err) => { | ||
| if (!callbackCalled) { | ||
| callbackCalled = true; | ||
| request.destroy(err); |
There was a problem hiding this comment.
I did a quick check on this, and I think when we reach the error callback of the request, the socket is already destroyed, so maybe here only need to destroy on line 238 ?
ce87e45 to
9cc19c9
Compare
Stub http.request to emit a synthetic error after response; assert destroy() is invoked with the expected err.code. Issue: HD-4352
9cc19c9 to
7ab390a
Compare
There was a problem hiding this comment.
The tests cover the post-response error cases well, but they all go through GET which never hits the stream branch in _handleRequest. The change from request.end to request.destroy at line 285 only runs when a stream is piped to the request, and nothing in the tests exercises that path.
It would be good to have a test that passes a stream that errors mid-transfer (e.g. through PUT) and checks that request.destroy gets called.
maeldonn
left a comment
There was a problem hiding this comment.
If @SylvainSenechal comment is right, we're missing the most important test.
On timeout or other errors the socket was left open; we now destroy the request so the socket is properly closed.
Issue: HD-4352