I'm using the @mysql/xdevapi npm package (version 8.0.22) with a local installation of mysql-8.0.15-winx64.
I have set pooling to enabled and attempted to retrieve a session from the client. If I do this before mysql is ready then I get an ECONNREFUSED exception which is expected, but the connection never appears to be released. If the pool size is one then all subsequent attempts to getSession
The exception is thrown from within the getSession method, so the session is not returned for me to call .end()
manually.
const mysqlx = require('@mysql/xdevapi');
const client = mysqlx.getClient(config, { pooling: { enabled: true, maxSize: 1, queueTimeout: 2000 } });
const session = await this.client.getSession(); // returns ECONNREFUSED exception
/*
wait for mysql to be ready and accepting connections
*/
const session = await this.client.getSession(); // returns connection pool queue timeout exception because the previous session hasn't been returned to the pool
How can I ensure that the aborted connection is returned to the pool?
This is a bug and I encourage you to report it at https://bugs.mysql.com/ using the
Connector for Node.js
category.The only workaround that comes to mind is re-creating the pool if the
getSession()
method returns a rejectedPromise
(with or without a specific error). For instance, something like:It's an ugly solution and there's a chance it might be hard to shoehorn into your design but, at least, it lets you enjoy the other benefits of a connection pool.
Disclaimer: I'm the lead developer of the MySQL X DevAPI Connector for Node.js