Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Treat aborts the same as before node 16
Browse files Browse the repository at this point in the history
Cherry-pick 79376fd
  • Loading branch information
flotwig authored and kevinvanrijn committed Sep 24, 2024
1 parent e202e96 commit d0a8bcc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions request.js
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,14 @@ Request.prototype.onRequestResponse = function (response) {
self.emit('end', chunk)
})
responseContent.on('error', function (error) {
if (error.code === 'ECONNRESET' && error.message === 'aborted' && self.listenerCount('error') === 0) {
// Node 16 causes aborts to emit errors if there is an error listener.
// Without this short-circuit, it will cause unhandled exceptions since
// there is not always an `error` listener on `self`, but there will
// always be an `error` listener on `responseContent`.
// @see https://github.com/nodejs/node/pull/33172
return
}
self.emit('error', error)
})
responseContent.on('close', function () { self.emit('close') })
Expand Down

0 comments on commit d0a8bcc

Please sign in to comment.