File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ var Connection = function(config) {
18
18
this . parsedStatements = { } ;
19
19
this . writer = new Writer ( ) ;
20
20
this . ssl = config . ssl || false ;
21
+ this . _ending = false ;
21
22
} ;
22
23
23
24
util . inherits ( Connection , EventEmitter ) ;
@@ -37,6 +38,11 @@ Connection.prototype.connect = function(port, host) {
37
38
} ) ;
38
39
39
40
this . stream . on ( 'error' , function ( error ) {
41
+ //don't raise ECONNRESET errors - they can & should be ignored
42
+ //during disconnect
43
+ if ( self . _ending && error . code == 'ECONNRESET' ) {
44
+ return ;
45
+ }
40
46
self . emit ( 'error' , error ) ;
41
47
} ) ;
42
48
@@ -263,6 +269,7 @@ Connection.prototype.end = function() {
263
269
//0x58 = 'X'
264
270
this . writer . add ( emptyBuffer ) ;
265
271
this . _send ( 0x58 ) ;
272
+ this . _ending = true ;
266
273
} ;
267
274
268
275
Connection . prototype . describe = function ( msg , more ) {
Original file line number Diff line number Diff line change 1
1
var helper = require ( __dirname + '/test-helper' ) ;
2
2
var Connection = require ( __dirname + '/../../../lib/connection' ) ;
3
- var con = new Connection ( { stream : new MemoryStream ( ) } ) ;
4
3
test ( "connection emits stream errors" , function ( ) {
4
+ var con = new Connection ( { stream : new MemoryStream ( ) } ) ;
5
5
assert . emits ( con , 'error' , function ( err ) {
6
6
assert . equal ( err . message , "OMG!" ) ;
7
7
} ) ;
8
8
con . connect ( ) ;
9
9
con . stream . emit ( 'error' , new Error ( "OMG!" ) ) ;
10
10
} ) ;
11
+
12
+ test ( 'connection emits ECONNRESET errors during normal operation' , function ( ) {
13
+ var con = new Connection ( { stream : new MemoryStream ( ) } ) ;
14
+ con . connect ( ) ;
15
+ assert . emits ( con , 'error' , function ( err ) {
16
+ assert . equal ( err . code , 'ECONNRESET' ) ;
17
+ } ) ;
18
+ var e = new Error ( 'Connection Reset' ) ;
19
+ e . code = 'ECONNRESET' ;
20
+ con . stream . emit ( 'error' , e ) ;
21
+ } ) ;
22
+
23
+ test ( 'connection does not emit ECONNRESET errors during disconnect' , function ( ) {
24
+ var con = new Connection ( { stream : new MemoryStream ( ) } ) ;
25
+ con . connect ( ) ;
26
+ var e = new Error ( 'Connection Reset' ) ;
27
+ e . code = 'ECONNRESET' ;
28
+ con . end ( ) ;
29
+ con . stream . emit ( 'error' , e ) ;
30
+ } ) ;
You can’t perform that action at this time.
0 commit comments