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

Update how the ECONNRESET error is caught when connection already closing #1438

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails if I revert the err.code back to err.errno. I made the assertion targeted so this doesn't accidentally test some other error condition.

});