不要怂,就是干,撸起袖子干!

Commit 7a6c60d7 by Sushant Committed by GitHub

fix(mssql): unexpected error event when connect fails, crashing node process (#10762)

1 parent e879460c
Showing with 12 additions and 5 deletions
...@@ -90,11 +90,14 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -90,11 +90,14 @@ class ConnectionManager extends AbstractConnectionManager {
connection.once('end', endHandler); connection.once('end', endHandler);
connection.once('connect', connectHandler); connection.once('connect', connectHandler);
if (config.dialectOptions && config.dialectOptions.debug) { /*
connection.on('debug', debugTedious.log.bind(debugTedious)); * Permanently attach this event before connection is even acquired
} * tedious sometime emits error even after connect(with error).
}).tap(resourceLock => { *
const connection = resourceLock.unwrap(); * If we dont attach this even that unexpected error event will crash node process
*
* E.g. connectTimeout is set higher than requestTimeout
*/
connection.on('error', error => { connection.on('error', error => {
switch (error.code) { switch (error.code) {
case 'ESOCKET': case 'ESOCKET':
...@@ -102,6 +105,10 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -102,6 +105,10 @@ class ConnectionManager extends AbstractConnectionManager {
this.pool.destroy(resourceLock); this.pool.destroy(resourceLock);
} }
}); });
if (config.dialectOptions && config.dialectOptions.debug) {
connection.on('debug', debugTedious.log.bind(debugTedious));
}
}).catch(error => { }).catch(error => {
if (!error.code) { if (!error.code) {
throw new sequelizeErrors.ConnectionError(error); throw new sequelizeErrors.ConnectionError(error);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!