Skip to content

Commit 389360e

Browse files
committed
Fix warning "packets out of order" when handling ER_CLIENT_INTERACTION_TIMEOUT
1 parent 1eef0a7 commit 389360e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lib/connection.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,6 @@ class Connection extends EventEmitter {
407407
this._paused_packets.push(packet);
408408
return;
409409
}
410-
if (packet) {
411-
if (this.sequenceId !== packet.sequenceId) {
412-
const err = new Error(
413-
`Warning: got packets out of order. Expected ${this.sequenceId} but received ${packet.sequenceId}`
414-
);
415-
err.expected = this.sequenceId;
416-
err.received = packet.sequenceId;
417-
this.emit('warn', err); // REVIEW
418-
// eslint-disable-next-line no-console
419-
console.error(err.message);
420-
}
421-
this._bumpSequenceId(packet.numPackets);
422-
}
423410
if (this.config.debug) {
424411
if (packet) {
425412
// eslint-disable-next-line no-console
@@ -458,6 +445,20 @@ class Connection extends EventEmitter {
458445
this.close();
459446
return;
460447
}
448+
if (packet) {
449+
// Note: when server closes connection due to inactivity, Err packet ER_CLIENT_INTERACTION_TIMEOUT from MySQL 8.0.24, sequenceId will be 0
450+
if (this.sequenceId !== packet.sequenceId) {
451+
const err = new Error(
452+
`Warning: got packets out of order. Expected ${this.sequenceId} but received ${packet.sequenceId}`
453+
);
454+
err.expected = this.sequenceId;
455+
err.received = packet.sequenceId;
456+
this.emit('warn', err); // REVIEW
457+
// eslint-disable-next-line no-console
458+
console.error(err.message);
459+
}
460+
this._bumpSequenceId(packet.numPackets);
461+
}
461462
const done = this._command.execute(packet, this);
462463
if (done) {
463464
this._command = this._commands.shift();

0 commit comments

Comments
 (0)