-
-
Notifications
You must be signed in to change notification settings - Fork 654
Open
Labels
Description
Upon fatal error any connection is set to "closed" state so that its addCommand would throw specific error, which has no code assigned, but has fatal=true flag (see _addCommandClosedState()).
When client attempts to call query() on such connection, this error is forwarded to command callback: cmd.onResult(err). However, if this is PromiseConnection, the error is passed via makeDoneCb() wrapper, which creates another error object to reject the promise but does not copy fatal property. As a result, client receives "closed-state" error without fatal flag. For non-Promise connections it works correctly.
It can be reproduced with something like this:
const mysql = require('mysql2/promise');
it('fatal add promise', async () => {
await startMockServer();
const conn = await mysql.createConnection(connectionOptions);
await shutMockServer();
try {
await conn.query('SELECT 1');
expect.fail();
} catch (err) {
expect(err).to.be.instanceOf(Error); // OK
expect(err.message).to.equal("Can't add new command when connection is in closed state"); // OK
expect(err.fatal).to.equal(true); // ERROR because `fatal` is undefined
}
});