File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -280,6 +280,7 @@ class NodeChannel {
280
280
} ) ;
281
281
282
282
self . _conn . on ( 'error' , self . _handleConnectionError ) ;
283
+ self . _conn . on ( 'end' , self . _handleConnectionTerminated ) ;
283
284
284
285
// Drain all pending messages
285
286
let pending = self . _pending ;
@@ -297,6 +298,13 @@ class NodeChannel {
297
298
}
298
299
}
299
300
301
+ _handleConnectionTerminated ( ) {
302
+ this . _error = new Error ( 'Connection was closed by server' ) ;
303
+ if ( this . onerror ) {
304
+ this . onerror ( this . _error ) ;
305
+ }
306
+ }
307
+
300
308
isEncrypted ( ) {
301
309
return this . _encrypted ;
302
310
}
@@ -326,6 +334,7 @@ class NodeChannel {
326
334
this . _open = false ;
327
335
if ( this . _conn ) {
328
336
this . _conn . end ( ) ;
337
+ this . _conn . removeListener ( 'end' , this . _handleConnectionTerminated ) ;
329
338
this . _conn . on ( 'end' , cb ) ;
330
339
} else {
331
340
cb ( ) ;
Original file line number Diff line number Diff line change @@ -40,11 +40,16 @@ class Pool {
40
40
}
41
41
42
42
acquire ( ) {
43
- if ( this . _pool . length > 0 ) {
44
- return this . _pool . pop ( ) ;
45
- } else {
46
- return this . _create ( this . _release ) ;
43
+ let resource ;
44
+ while ( this . _pool . length ) {
45
+ resource = this . _pool . pop ( ) ;
46
+
47
+ if ( this . _validate ( resource ) ) {
48
+ return resource ;
49
+ }
47
50
}
51
+
52
+ return this . _create ( this . _release ) ;
48
53
}
49
54
50
55
_release ( resource ) {
You can’t perform that action at this time.
0 commit comments