Skip to content

Commit 686a56e

Browse files
authored
Merge pull request #1438 from kneemer/master
Update how the ECONNRESET error is caught when connection already closing
2 parents 1448ae8 + fbd92ed commit 686a56e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class Connection extends EventEmitter {
174174
this.connectTimeout = null;
175175
}
176176
// Do not throw an error when a connection ends with a RST,ACK packet
177-
if (err.errno === 'ECONNRESET' && this._closing) {
177+
if (err.code === 'ECONNRESET' && this._closing) {
178178
return;
179179
}
180180
this._handleFatalError(err);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const common = require('../../common')
5+
6+
const error = new Error('read ECONNRESET');
7+
error.code = 'ECONNRESET'
8+
error.errno = -54
9+
error.syscall = 'read';
10+
11+
const connection = common.createConnection();
12+
13+
// Test that we ignore a ECONNRESET error if the connection
14+
// is already closing, we close and then emit the error
15+
connection.query(`select 1`, (err, rows) => {
16+
assert.equal(rows[0]['1'], 1);
17+
connection.close();
18+
connection.stream.emit('error', error);
19+
});
20+
21+
process.on('uncaughtException', err => {
22+
assert.notEqual(err.code, 'ECONNRESET')
23+
});

0 commit comments

Comments
 (0)