From 89784e7a4356118715c4a127670164de5c1669f3 Mon Sep 17 00:00:00 2001 From: Anthony Guo Date: Sat, 2 Jun 2018 02:14:46 -0700 Subject: [PATCH 1/5] Add a 10 second timeout for in _poolCreate method for tedious --- lib/tedious.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/tedious.js b/lib/tedious.js index 80f490bb..91a3a3be 100644 --- a/lib/tedious.js +++ b/lib/tedious.js @@ -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) @@ -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 From 0493b7a68cc7dd91fdf89f5e81ca0a961ad1ceda Mon Sep 17 00:00:00 2001 From: Anthony Guo Date: Sat, 2 Jun 2018 02:21:48 -0700 Subject: [PATCH 2/5] bugfix --- lib/tedious.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tedious.js b/lib/tedious.js index 91a3a3be..345bbfc8 100644 --- a/lib/tedious.js +++ b/lib/tedious.js @@ -231,7 +231,7 @@ 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 + let emittedConnectEvent = false tedious.once('connect', err => { emittedConnectEvent = true From 53c44574ffd5bca6d94bbff1bdf37855e0ebef8c Mon Sep 17 00:00:00 2001 From: Will Morgan Date: Mon, 23 Jul 2018 10:26:56 +0100 Subject: [PATCH 3/5] Allow configurable connection timeout --- lib/tedious.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tedious.js b/lib/tedious.js index 345bbfc8..12a5ec79 100644 --- a/lib/tedious.js +++ b/lib/tedious.js @@ -246,9 +246,9 @@ class ConnectionPool extends base.ConnectionPool { setTimeout(() => { if (!emittedConnectEvent) { - reject(new base.ConnectionError('Tedious connection timed out after 10 seconds')) + reject(new base.ConnectionError('Tedious connection timed out after options.connectTimeout')) } - }, 10 * 1000) + }, cfg.options.connectTimeout) tedious.on('error', err => { if (err.code === 'ESOCKET') { From 5c9442b3bf0693b2c62bd9078c0d63d8f51c4469 Mon Sep 17 00:00:00 2001 From: Will Morgan Date: Mon, 23 Jul 2018 10:45:07 +0100 Subject: [PATCH 4/5] Reject factory creates when an error occurs --- lib/tedious.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tedious.js b/lib/tedious.js index 12a5ec79..9885ccc7 100644 --- a/lib/tedious.js +++ b/lib/tedious.js @@ -253,10 +253,12 @@ class ConnectionPool extends base.ConnectionPool { tedious.on('error', err => { if (err.code === 'ESOCKET') { tedious.hasError = true + reject(err) return } this.emit('error', err) + reject(err) }) if (this.config.debug) { From 6f484ffe276bddc9a1c77e8dc8ffe5f07456352c Mon Sep 17 00:00:00 2001 From: Will Morgan Date: Sun, 5 Aug 2018 11:14:59 +0100 Subject: [PATCH 5/5] Rely on Tedious; remove setTimeout connect timeout catcher --- lib/tedious.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/tedious.js b/lib/tedious.js index 9885ccc7..fc29a4b3 100644 --- a/lib/tedious.js +++ b/lib/tedious.js @@ -231,10 +231,8 @@ 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)) - let emittedConnectEvent = false tedious.once('connect', err => { - emittedConnectEvent = true if (err) { err = new base.ConnectionError(err) return reject(err) @@ -244,12 +242,6 @@ class ConnectionPool extends base.ConnectionPool { resolve(tedious) }) - setTimeout(() => { - if (!emittedConnectEvent) { - reject(new base.ConnectionError('Tedious connection timed out after options.connectTimeout')) - } - }, cfg.options.connectTimeout) - tedious.on('error', err => { if (err.code === 'ESOCKET') { tedious.hasError = true