Skip to content

[BUG] Connection pool grows correctly but never shrinks back #445

@fabiobuono87

Description

@fabiobuono87

Describe your system

  • odbc Package Version: 2.4.8
  • ODBC Driver: IBM DB2 ODBC DRIVER
  • Database Name: DB2
  • Database OS: IBM i (AS/400)
  • Node.js Version: 18.17.1
  • Node.js OS: IBM i

Describe the bug
When using the built-in connection pool with shrink: true, the pool grows beyond initialSize under load but does not shrink back once the load is gone. After all queries have completed and all connections have been released, pool.poolSize remains permanently greater than initialSize, even after a long idle period.

This behavior occurs both when using pool.query() and when explicitly acquiring and releasing connections using pool.connect() and connection.close().

Expected behavior
With shrink: true, once all connections are released and the system becomes idle, the pool should eventually shrink back to initialSize, or at least have a documented, deterministic behavior regarding when or if shrinking occurs.

To Reproduce

  1. Create a pool with the following options:
    const pool = await odbc.pool({
      connectionString,
      initialSize: 2,
      incrementSize: 1,
      maxSize: 20,
      shrink: true
    });
  2. Run multiple queries in parallel to force the pool to grow
await Promise.all(
Array.from({ length: 10 }, () =>
  pool.query("SELECT 1")
)
);

#or using explicit connections:

const conn = await pool.connect();
await conn.query("SELECT 1");
await conn.close();
  1. Wait until all queries have completed.
  2. Log pool.poolSize

Additional context
Calling connection.close() seems to only return the connection to the pool and does not close the actual database connection. There does not appear to be a documented idle timeout or automatic cleanup of extra connections. As a result, once the pool grows beyond initialSize, it stays larger even when the application is idle. This makes it hard to control the total number of open database connections.

Is this behavior expected by design? If so, it would be helpful to clarify this in the documentation or provide a deterministic way to shrink or evict idle connections.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions