http: don't destroy socket after request completes · nodejs/node@77d8f17 · GitHub
Skip to content

Commit 77d8f17

Browse files
barathraj048aduh95
authored andcommitted
http: don't destroy socket after request completes
Aborting a ClientRequest after the request has finished sending and the response has fully arrived has nothing left to cancel. destroy() still called socket.destroy(err), but the resulting 'error' is emitted on a later tick. In that window, responseKeepAlive() has already removed socketErrorListener while handing the socket back to the agent's free pool, so the error lands with no listener and crashes the process. Skip the socket destroy when there is nothing left to cancel. This matches the existing behavior of keepAlive: false requests, which already drop any unread buffered response data in this situation. Fixes: #65938 Signed-off-by: Barath <barathraj048@gmail.com> PR-URL: #65952 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2b1701f commit 77d8f17

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎lib/_http_client.js‎

Lines changed: 8 additions & 0 deletions
Lines changed: 57 additions & 0 deletions

0 commit comments

Comments
 (0)