diff --git a/lib/core/client.js b/lib/core/client.js index 525a4b7845f..9b742674b4d 100644 --- a/lib/core/client.js +++ b/lib/core/client.js @@ -798,7 +798,10 @@ function socketPause () { // TODO: Pause parser. if (this._handle && this._handle.reading) { this._handle.reading = false - this._handle.readStop() + const err = this._handle.readStop() + if (err) { + this.destroy(util.errnoException(err, 'read')) + } } } @@ -806,7 +809,10 @@ function socketResume () { // TODO: Resume parser. if (this._handle && !this._handle.reading) { this._handle.reading = true - this._handle.readStart() + const err = this._handle.readStart() + if (err) { + this.destroy(util.errnoException(err, 'read')) + } } } diff --git a/lib/core/util.js b/lib/core/util.js index bf3a00ab607..397576c7ae1 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -3,6 +3,7 @@ const assert = require('assert') const { kDestroyed } = require('./symbols') const { IncomingMessage } = require('http') +const util = require('util') function nop () {} @@ -76,8 +77,20 @@ function isBuffer (buffer) { return buffer instanceof Uint8Array || Buffer.isBuffer(buffer) } +function errnoException (code, syscall) { + const name = util.getSystemErrorName(code) + + const err = new Error(`${syscall} ${name}`) + err.errno = err + err.code = code + err.syscall = syscall + + return err +} + module.exports = { nop, + errnoException, isStream, isDestroyed, parseHeaders,