Skip to content

Commit

Permalink
fix: handle socket handle errors (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag authored Sep 25, 2020
1 parent f9f0387 commit 4208071
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,15 +798,21 @@ 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'))
}
}
}

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'))
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const assert = require('assert')
const { kDestroyed } = require('./symbols')
const { IncomingMessage } = require('http')
const util = require('util')

function nop () {}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4208071

Please sign in to comment.