Skip to content

Pool does not detect nor recover from failover #2945

Open
@aguglie

Description

@aguglie

Hello,
I'm using mysql2 with a promise pool setup as follows:

const pool = mysql.createPool({
    port: parseInt(mysqlPort, 10),
    waitForConnections: true,
    connectionLimit: 5,
    maxIdle: 5,
    idleTimeout: 60000,
    queueLimit: 0,
    host: mysqlHost,
    user: mysqlUser,
    password: mysqlPassword,
    database: mysqlDatabase,
    ssl: mysqlUseSsl ? {
        rejectUnauthorized: false,
        ca: await axios.get('https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem', { responseType: 'arraybuffer' })
            .then(response => response.data.toString('utf-8'))
    } : undefined,
    timezone: 'local'
});

When I trigger a manual failover from the RDS console (controlled failover), everything works as expected. The connection is logged as lost with the message "Connection lost: The server closed the connection." and a new connection is established on the next .query().

However, when a brutal failover occurs (e.g., the DBMS crashes), mysql2 does not detect that the connection has been lost, (indeed it's not closed by the DBMS since it crashed). The connection remains hanging indefinitely, and no reconnection attempt is made.

Is there a recommended way to handle this scenario with the current library? If not, do you have suggestion on how implement a more robust connection failure detection and recovery mechanism?

Expected Behavior:
When a brutal failover occurs, the library should detect the lost connection and discard it, so that a new connection can be established automatically.

Observed Behavior:
The connection hangs indefinitely without detecting the disconnection.

Steps to Reproduce:
Set up a connection pool as described above.
Trigger a brutal failover by crashing the DBMS.
Attempt to execute a query.

Environment:
mysql2 version: 3.9.9
Node.js version: 18
Database: Amazon RDS MySQL

Thank you :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions