diff --git a/lib/pool.js b/lib/pool.js index 3fcafbc..2dd0787 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -32,8 +32,8 @@ class Pool { checkTime: args.checkTime ?? 120000, // how often to run the livliness check, will not run when set to 0 maxLimit: args.maxLimit ?? 200, connectionRetryLimit: args.connectionRetryLimit || 5, - skipCheckLivelinessOnRelease : args.skipCheckLivelinessOnRelease ?? false, - livelinessCheck: args.livelinessCheck ?? 'query' + skipCheckLivelinessOnRelease: args.skipCheckLivelinessOnRelease ?? false, + livelinessCheck: args.livelinessCheck ?? "query", }; this.poolId = args.id || new Date().getTime(); @@ -81,9 +81,11 @@ class Pool { let retvalue = true; if (this.config.skipCheckLivelinessOnRelease === false) { if (connection.hasFailed() === false) { - if (this.config.livelinessCheck.toLowerCase() === 'query') { + if (this.config.livelinessCheck.toLowerCase() === "query") { try { - const result = await connection.execute("SELECT 1 AS VALUE FROM DUAL"); + const result = await connection.execute( + "SELECT 1 AS VALUE FROM DUAL" + ); await result.close(); } catch (e) { retvalue = false; @@ -141,8 +143,9 @@ class Pool { } async _populationCheck() { - if (Object.keys(this.all_connections).length < this.config.maxLimit && - this.free_connections.length < this.config.minAvailable + if ( + Object.keys(this.all_connections).length < this.config.maxLimit && + this.free_connections.length < this.config.minAvailable ) { let newConn = await this._createConnection(); this.free_connections.push(newConn); @@ -205,6 +208,12 @@ class Pool { } async _createConnection() { + if ( + Object.keys(this.all_connections).length >= this.config.maxLimit && + this.free_connections.length === 0 + ) { + throw new Error("connection hard limit reached"); + } let error; let connectionMade; let tries = 0; @@ -275,10 +284,11 @@ class Pool { try { await connection._defaultClose(); } catch (e) { - throw e + throw e; } - if (Object.keys(this.all_connections).length < this.config.maxLimit && - this.free_connections.length < this.config.minAvailable + if ( + Object.keys(this.all_connections).length < this.config.maxLimit && + this.free_connections.length < this.config.minAvailable ) { let newConn = await this._createConnection(); this.free_connections.push(newConn);