File tree 3 files changed +7
-11
lines changed
3 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -223,8 +223,10 @@ Connection.prototype._addListeners = function _addListeners(socket) {
223
223
if ( cb ) {
224
224
self . _state . receive = null ; // a callback should be called only once
225
225
cb ( err ) ;
226
- } else {
226
+ } else if ( self . listeners ( 'error' ) . length ) {
227
227
self . emit ( 'error' , err ) ;
228
+ } else {
229
+ debug ( 'onerror' , err ) ;
228
230
}
229
231
}
230
232
socket . on ( 'error' , onerror ) ;
@@ -239,7 +241,7 @@ Connection.prototype._addListeners = function _addListeners(socket) {
239
241
function onend ( ) {
240
242
var err = new Error ( 'Connection closed by server' ) ;
241
243
err . code = 'EHDBCLOSE' ;
242
- socket . emit ( 'error' , err ) ;
244
+ onerror ( err ) ;
243
245
}
244
246
socket . on ( 'end' , onend ) ;
245
247
} ;
Original file line number Diff line number Diff line change @@ -78,11 +78,6 @@ ConnectionManager.prototype._openConnectionMultiDbCase = function _openConnectio
78
78
}
79
79
}
80
80
81
- function onError ( err ) {
82
- cb ( err ) ;
83
- }
84
- conn . on ( 'error' , onError ) ;
85
-
86
81
function handleError ( err ) {
87
82
conn . close ( ) ;
88
83
cb ( err ) ;
@@ -99,7 +94,6 @@ ConnectionManager.prototype._openConnectionMultiDbCase = function _openConnectio
99
94
}
100
95
101
96
if ( info . isConnected ) {
102
- conn . removeListener ( 'error' , onError ) ;
103
97
cb ( null ) ;
104
98
} else {
105
99
conn . _closeSilently ( ) ;
Original file line number Diff line number Diff line change @@ -513,12 +513,12 @@ describe('hdb', function () {
513
513
databaseName : 'DB0'
514
514
} ) ;
515
515
516
- client . _connection . fetchDbConnectInfo = function ( ) {
517
- client . _connection . emit ( 'error' , new Error ( 'Network error emitted ' ) ) ;
516
+ client . _connection . fetchDbConnectInfo = function ( options , cb ) {
517
+ cb ( new Error ( 'Network error' ) ) ;
518
518
} ;
519
519
520
520
client . connect ( function ( err ) {
521
- err . message . should . equal ( 'Could not connect to any host: [ localhost:30013 - Network error emitted ]' ) ;
521
+ err . message . should . equal ( 'Could not connect to any host: [ localhost:30013 - Network error ]' ) ;
522
522
done ( ) ;
523
523
} ) ;
524
524
} ) ;
You can’t perform that action at this time.
0 commit comments