When using the standard function to create a HikariTransactor from a config, fromHikariConfigWithResEffect creates an ExecutionContext whose pool size is equal to Hikari’s maximumPoolSize. As a result, getConnection calls are also limited by that pool.
If the ExecutionContext pool becomes exhausted, additional connection attempts wait before they even reach Hikari. Because of this, Hikari’s connectionTimeout is not observed at the expected time.
For example, with maximumPoolSize = 1, if multiple queries are running at the same time and network requests are no longer reaching the database, the queries fail one after another with a timeout error. With connectionTimeout = 1000 ms, the last query may fail only after about 10 seconds. Also, in this case, cats-effect timeouts do not work as expected.
I think it would be worth providing a function that creates a pool with a bounded queue, as described in this comment on another issue.
Another option would be to provide a function that limits the number of concurrent connection attempts using a Semaphore, with a timeout on acquire.
When using the standard function to create a
HikariTransactorfrom a config,fromHikariConfigWithResEffectcreates anExecutionContextwhose pool size is equal to Hikari’smaximumPoolSize. As a result,getConnectioncalls are also limited by that pool.If the
ExecutionContextpool becomes exhausted, additional connection attempts wait before they even reach Hikari. Because of this, Hikari’sconnectionTimeoutis not observed at the expected time.For example, with
maximumPoolSize = 1, if multiple queries are running at the same time and network requests are no longer reaching the database, the queries fail one after another with a timeout error. WithconnectionTimeout = 1000 ms, the last query may fail only after about 10 seconds. Also, in this case, cats-effect timeouts do not work as expected.I think it would be worth providing a function that creates a pool with a bounded queue, as described in this comment on another issue.
Another option would be to provide a function that limits the number of concurrent connection attempts using a
Semaphore, with a timeout onacquire.