Open
Description
Sample code:
import { createPool } from "mysql2";
const connection = createPool({
host: 'localhost',
user: 'user',
password: 'pass',
});
try {
for await (const row of connection.query("SELECT * FROM big_table").stream()) {
// handle row here
}
} catch (e) {
// connection errors are not caught here
console.log('caught error', e);
}
If any connection errors occur during the command execution, they will not be caught while iterating over the rows.
After investigation I found the issue to be in Connection.notifyError
here
Lines 224 to 230 in 88587c6
From what I see, the error will be passed to the command only if the command was executed with a callback.
A solution that seems to fix the issue is to also emit the error to the command like this:
if (this._command) {
this._command.emit('error', err);
}
With the above change the error will be emitted to the command, and will also be thrown when iterating over the stream.
Can be reproduced by running a slow query like SELECT SLEEP(30)
and then issue a KILL "connection id"
Metadata
Metadata
Assignees
Labels
No labels