Skip to content

Commit

Permalink
fix: ensure we abort a request that emits error on the response body (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Feb 24, 2022
1 parent 44e8701 commit 5565cde
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/index.js
Expand Up @@ -214,6 +214,13 @@ const fetch = (url, opts) => {
signal && signal.removeEventListener('abort', abortAndFinalize))

const body = new Minipass()
// if an error occurs, either on the response stream itself, on one of the
// decoder streams, or a response length timeout from the Body class, we
// forward the error through to our internal body stream. If we see an
// error event on that, we call finalize to abort the request and ensure
// we don't leave a socket believing a request is in flight.
// this is difficult to test, so lacks specific coverage.
body.on('error', finalize)
// exceedingly rare that the stream would have an error,
// but just in case we proxy it to the stream in use.
res.on('error', /* istanbul ignore next */ er => body.emit('error', er))
Expand Down

0 comments on commit 5565cde

Please sign in to comment.