Skip to content

Commit

Permalink
[CONJS-288] ensure pool timeout error give details #268
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Apr 24, 2024
1 parent 2cbeb34 commit 75d97f9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Pool extends EventEmitter {
//*****************************************************************

_doCreateConnection(resolve, reject, timeoutEnd) {
this._createConnection()
this._createConnection(timeoutEnd)
.then((conn) => {
if (this.#closed) {
conn.forceEnd(
Expand Down Expand Up @@ -395,8 +395,14 @@ class Pool extends EventEmitter {
return info;
}

async _createConnection() {
const conn = new Connection(this.opts.connOptions);
async _createConnection(timeoutEnd) {
// ensure setting a connection timeout if no connection timeout is set
const minTimeout = Math.max(1, timeoutEnd - 100);
const connectionOpts =
!this.opts.connOptions.connectTimeout || this.opts.connOptions.connectTimeout > minTimeout
? Object.assign({}, this.opts.connOptions, { connectTimeout: minTimeout })
: this.opts.connOptions;
const conn = new Connection(connectionOpts);
await conn.connect();
const pool = this;
conn.forceEnd = conn.end;
Expand Down

0 comments on commit 75d97f9

Please sign in to comment.