diff --git a/lib/index.js b/lib/index.js index 267ecbf..890f117 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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))