-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Hello there,
I noticed an unexpected behaviour in mariadb version 3.4.5: When setting minimumIdle to 0, queries fail with a pool timeout error after acquireTimeout is reached.
Reproduction:
const mariadb = require('mariadb')
const pool = mariadb.createPool({
host : 'localhost',
port : 3306,
user : 'test',
password : 'test',
database : 'test',
minimumIdle : 0,
acquireTimeout : 5 * 1000,
})
const main = async () => {
try {
await pool.query('SELECT SLEEP(0.5)')
} finally {
await pool.end()
}
}
main()
.then(() => console.log('done'))
.catch(err => console.error(err))When not setting minimumIdle or when setting it to a positive value this works as expected but when setting it to 0, it logs this error:
SqlError: (conn:-1, no: 45028, SQLState: HY000) pool timeout: failed to retrieve a connection from pool after 5004ms
(pool connections: active=0 idle=0 limit=10)
at module.exports.createError (/home/me/test/node_modules/.pnpm/[email protected]/node_modules/mariadb/lib/misc/errors.js:66:10)
at Pool._rejectTimedOutRequest (/home/me/test/node_modules/.pnpm/[email protected]/node_modules/mariadb/lib/pool.js:347:33)
at Pool._checkRequestTimeouts (/home/me/test/node_modules/.pnpm/[email protected]/node_modules/mariadb/lib/pool.js:315:14)
at listOnTimeout (node:internal/timers:588:17)
at process.processTimers (node:internal/timers:523:7) {
sqlMessage: 'pool timeout: failed to retrieve a connection from pool after 5004ms\n' +
' (pool connections: active=0 idle=0 limit=10)',
sql: null,
fatal: false,
errno: 45028,
sqlState: 'HY000',
code: 'ER_GET_CONNECTION_TIMEOUT'
}
Even with no idle connections auto-created on pool instanciation (minimumIdle: 0) I would expect the query to work.
I think this happens because of check this.#idleConnections.length < this.opts.minimumIdle in _shouldCreateMoreConnections() (see https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/3.4.5/lib/pool.js#L472). When changing the check to (this.#idleConnections.length < this.opts.minimumIdle) || this.opts.minimumIdle <= 0 it works fine.
Is this expected behaviour or a bug?