lib/pool-base.js
function(pool) {
    if (
      !connectionInCreation &&
      pool.idleConnections() < opts.minimumIdle &&
      pool.totalConnections() < opts.connectionLimit &&
      !closed
    ) {
      connectionInCreation = true;
      process.nextTick(() => {
        const timeoutEnd = Date.now() + opts.initializationTimeout;
        if (!closed) {
          connectionCreationLoop(pool, 0, timeoutEnd)
            .then(conn => {
              if (closed) {
                return conn.forceEnd().catch(err => {});
              }
              addPoolConnection(pool, conn);
            })
            .catch(err => {
              if (pool.totalConnections() === 0) {
                const task = taskQueue.shift();
                if (task) {
                  firstTaskTimeout = clearTimeout(firstTaskTimeout);
                  process.nextTick(task.reject, err);
                  resetTimeoutToNextTask();
                }
              } else if (!closed) {
                console.error(
                  `pool fail to create connection (${err.message})`
                );
              }

              //delay next try
              setTimeout(() => {
                connectionInCreation = false;
                if (taskQueue.size() > 0) {
                  ensurePoolSize(pool);
                }
              }, 500);
            });
        }
      });
    }
  }
function(pool) {
    if (
      !connectionInCreation &&
      pool.idleConnections() < opts.minimumIdle &&
      pool.totalConnections() < opts.connectionLimit &&
      !closed
    ) {
      connectionInCreation = true;
      process.nextTick(() => {
        const timeoutEnd = Date.now() + opts.initializationTimeout;
        if (!closed) {
          connectionCreationLoop(pool, 0, timeoutEnd)
            .then(conn => {
              if (closed) {
                return conn.forceEnd().catch(err => {});
              }
              addPoolConnection(pool, conn);
            })
            .catch(err => {
              if (pool.totalConnections() === 0) {
                const task = taskQueue.shift();
                if (task) {
                  firstTaskTimeout = clearTimeout(firstTaskTimeout);
                  process.nextTick(task.reject, err);
                  resetTimeoutToNextTask();
                }
              } else if (!closed) {
                console.error(
                  `pool fail to create connection (${err.message})`
                );
              }

              //delay next try
              setTimeout(() => {
                connectionInCreation = false;
                if (taskQueue.size() > 0) {
                  ensurePoolSize(pool);
                }
              }, 500);
            });
        }
      });
    }
  }
function ( pool ) { if ( ! connectionInCreation && pool . idleConnections ( ) < opts . minimumIdle && pool . totalConnections ( ) < opts . connectionLimit && ! closed ) { connectionInCreation = true ; process . nextTick ( ( ) => { const timeoutEnd = Date . now ( ) + opts . initializationTimeout ; if ( ! closed ) { connectionCreationLoop ( pool , 0 , timeoutEnd ) . then ( conn => { if ( closed ) { return conn . forceEnd ( ) . catch ( err => { } ) ; } addPoolConnection ( pool , conn ) ; } ) . catch ( err => { if ( pool . totalConnections ( ) === 0 ) { const task = taskQueue . shift ( ) ; if ( task ) { firstTaskTimeout = clearTimeout ( firstTaskTimeout ) ; process . nextTick ( task . reject , err ) ; resetTimeoutToNextTask ( ) ; } } else if ( ! closed ) { console . error ( ` ${ err . message } ` ) ; } //delay next try setTimeout ( ( ) => { connectionInCreation = false ; if ( taskQueue . size ( ) > 0 ) { ensurePoolSize ( pool ) ; } } , 500 ) ; } ) ; } } ) ; } }
Grow pool connections until reaching connection limit.
Grow pool connections until reaching connection limit .