Closed
Description
When calling PoolCluster.getConnection(id)
with an invalid id
it may return a connection that does not match exactly.
The last character of id
is removed, and any connection ids that start with the new id-last character
will be returned. The expected behavior (and the behavior in mysqljs/mysql) is that a POOL_NOEXIST
error should be thrown.
import mysql from "mysql2/promise";
(async () => {
const poolCluster = mysql.createPoolCluster();
poolCluster.add("129", {
user: "root",
database: "exampledb",
});
poolCluster.add("12", {
user: "root",
database: "exampledb",
});
let connection = await poolCluster.getConnection("125");
// connection may be ID 129 or ID 12. Should be POOL_NOEXIST error.
await connection.query("SELECT 1");
poolCluster.end();
})();