Skip to content

PoolCluster.getConnection(id) can return incorrect PoolCluster #3450

Closed
@uPaymeiFixit

Description

@uPaymeiFixit

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();
})();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions