Skip to content

Commit

Permalink
Add a 10 second timeout for in _poolCreate method for tedious
Browse files Browse the repository at this point in the history
  • Loading branch information
jacqt authored and willmorgan committed Jul 23, 2018
1 parent 528bb62 commit 89784e7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/tedious.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ class ConnectionPool extends base.ConnectionPool {
IDS.add(tedious, 'Connection')
debug('pool(%d): connection #%d created', IDS.get(this), IDS.get(tedious))
debug('connection(%d): establishing', IDS.get(tedious))
const emittedConnectEvent = false

tedious.once('connect', err => {
emittedConnectEvent = true
if (err) {
err = new base.ConnectionError(err)
return reject(err)
Expand All @@ -242,6 +244,12 @@ class ConnectionPool extends base.ConnectionPool {
resolve(tedious)
})

setTimeout(() => {
if (!emittedConnectEvent) {
reject(new base.ConnectionError('Tedious connection timed out after 10 seconds'))
}
}, 10 * 1000)

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

0 comments on commit 89784e7

Please sign in to comment.