node-mssql: How/where to handle ESOCKET/ECONNRESET error

I tried to listen for error event, but as I saw in source code (tedious.js), ESOCKET event is ignored and nothing is emitted. I could see ECONNRESET in debug however. So how can I handle this event correctly? Occasionally this error occurs and then all requests are time-outed.

tedious.js

tedious.on('error', err => {
  if (err.code === 'ESOCKET') {
    tedious.hasError = true
    return
  }

  this.emit('error', err)
})

if (this.config.debug) {
  tedious.on('debug', this.emit.bind(this, 'debug', tedious))
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 16

Most upvoted comments

I this error when running larger queries, queries run fine in sql but lose connection when running through Transaction or Request RequestError: Connection lost - read ECONNRESET

keepactive:true helps

I don’t think its for the library to be making calls on when to try to reconnect to the DB. If the initial probe connection fails there’s no reason to try again. When new connections are added to the pool they try to connect and if they fail the connection is discarded and a new one obtained until the pool is depleted of working connections. If no new connections can be established the pool becomes “unhealthy”. It’s up to the developer to decide how to handle unhealthy pools or individual connections that go bad.

I’m not sure this issue needs to be left open, I think it’s being handled as expected now.