Skip to content

Why thin/pool _scanIdleConnection pops only last _freeConnectionList item? #1633

@boriborm

Description

@boriborm

Hello,
File thin/pool.js has procedure

//---------------------------------------------------------------------------
  // scanIdleConnection()
  //
  // scan connection list and removes idle connections from pool
  //---------------------------------------------------------------------------
  _scanIdleConnection() {
    while ((this._usedConnectionList.size + this._freeConnectionList.length) >
        this._poolMin && this._freeConnectionList.length > 0) {
      const conn = this._freeConnectionList[this._freeConnectionList.length - 1];
      if (Date.now() - conn._lastTimeUsed < this._poolTimeout * 1000) {
        break;
      }

      this.eventEmitter.emit('_removePoolConnection', conn);
      this._freeConnectionList.pop();
    }

    this._schedulerJob = null;
    this._setScheduler();
  }

Why in cycle pops only last elements of array _freeConnectionList?
I have some web requests. Each request get connection from the pool. First connection releases and pushes to _freeConnectionList and second connection pushes to _freeConnectionList. _lastTimeUsed of first connection may be earlier then second connection. While second connection did not timeout, while breakes and first connection with timeout will not pop. Other requests (not in same time) get new connection from last element of _freeConnectionList. This is real second connection. _lastTimeUsed of second connection changes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions