Skip to content

Commit

Permalink
Merge pull request #1438 from kneemer/master
Browse files Browse the repository at this point in the history
Update how the ECONNRESET error is caught when connection already closing
  • Loading branch information
sidorares authored Nov 24, 2021
2 parents 1448ae8 + fbd92ed commit 686a56e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Connection extends EventEmitter {
this.connectTimeout = null;
}
// Do not throw an error when a connection ends with a RST,ACK packet
if (err.errno === 'ECONNRESET' && this._closing) {
if (err.code === 'ECONNRESET' && this._closing) {
return;
}
this._handleFatalError(err);
Expand Down
23 changes: 23 additions & 0 deletions test/integration/connection/test-connection-reset-while-closing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const assert = require('assert');
const common = require('../../common')

const error = new Error('read ECONNRESET');
error.code = 'ECONNRESET'
error.errno = -54
error.syscall = 'read';

const connection = common.createConnection();

// Test that we ignore a ECONNRESET error if the connection
// is already closing, we close and then emit the error
connection.query(`select 1`, (err, rows) => {
assert.equal(rows[0]['1'], 1);
connection.close();
connection.stream.emit('error', error);
});

process.on('uncaughtException', err => {
assert.notEqual(err.code, 'ECONNRESET')
});

0 comments on commit 686a56e

Please sign in to comment.