Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] No new connections being made on empty pool when maxSize is less than incrementSize #397

Open
popeliv opened this issue Aug 20, 2024 · 0 comments

Comments

@popeliv
Copy link

popeliv commented Aug 20, 2024

Describe your system

  • odbc Package Version: 2.4.8
  • ODBC Driver: Progress OpenEdge ODBC Driver 8.0.0
  • Database Name: OpenEdge
  • Database Version: 11.7
  • Database OS: Windows
  • Node.js Version: 18.20.2
  • Node.js OS: linux/amd64

Describe the bug
This bug is related to pooling.

On an initialized empty pool (with no active connections), if the incrementSize is larger than the maxSize, if no new connections are being created, no new connections can be created.

For example:
If there is only one connection in a pool and that single connection dies (i.e. the socket gets closed), the connection needs to be closed manually with nativeClose and poolSize needs to be decremented manually. We need to call nativeClose instead of close because close will just release that dead connection back into the pool without closing it.
In this state, no new connection can be made.

I discovered this with a pool maxSize of 5, initialSize of 1 and without defining the incrementSize (it defaults to 10).

Expected behavior
A new connection should be made on an empty pool regardless of the maxSize and incrementSize settings on the pool.

To Reproduce

  1. Connect to database using a pool with options { maxSize: 5, initialSize: 1, reuseConnections: true }
  2. Force close the connection socket from on the database server
  3. Call nativeClose on the connection in the pool and decrement the poolSize
  4. Call connect on the pool to obtain a new connection.

Code

  const query = async (query) => {
    let odbcConnection = await connect()
    for (let tries = 0; tries < maxNumberOfTries; tries++) {
     try {
        const res = await odbcConnection.query(query)
        await odbcConnection.close()
        return res
      } catch (error) {
        if (
          error.odbcErrors?.[0]?.message ===
          "[DataDirect][ODBC Progress OpenEdge Wire Protocol driver]Socket closed."
        ) { 
          await odbcConnection.nativeClose()
          this.pool.poolSize--
          odbcConnection = await connect()
        }
      }
    }
    throw new Error("Failed to query the database")
  }
  • The offending code:
    I believe the issue stems from this if statement in /lib/Pool.js on line 211 and 212
    if (this.connectionsBeingCreatedCount <= this.waitingConnectionWork.length &&

The main issue here is that it doesn't make sense for incrementSize to be less than maxSize, but the default incrementSize is 10, so any maxSize less than that can cause issues.

Maybe the best way to handle this would be set the default incrementSize to min(maxSize, 10), or change the logic in the if condition to handle this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant