Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool does not detect nor recover from failover #2945

Open
aguglie opened this issue Aug 12, 2024 · 0 comments
Open

Pool does not detect nor recover from failover #2945

aguglie opened this issue Aug 12, 2024 · 0 comments

Comments

@aguglie
Copy link

aguglie commented Aug 12, 2024

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant