File tree 2 files changed +18
-4
lines changed
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,7 @@ class NodeChannel {
276
276
} ) ;
277
277
278
278
self . _conn . on ( 'error' , self . _handleConnectionError ) ;
279
+ self . _conn . on ( 'end' , self . _handleConnectionTerminated ) ;
279
280
280
281
// Drain all pending messages
281
282
let pending = self . _pending ;
@@ -293,6 +294,13 @@ class NodeChannel {
293
294
}
294
295
}
295
296
297
+ _handleConnectionTerminated ( ) {
298
+ this . _error = new Error ( 'Connection was closed by server' ) ;
299
+ if ( this . onerror ) {
300
+ this . onerror ( this . _error ) ;
301
+ }
302
+ }
303
+
296
304
/**
297
305
* Write the passed in buffer to connection
298
306
* @param {NodeBuffer } buffer - Buffer to write
@@ -318,6 +326,7 @@ class NodeChannel {
318
326
this . _open = false ;
319
327
if ( this . _conn ) {
320
328
this . _conn . end ( ) ;
329
+ this . _conn . removeListener ( 'end' , this . _handleConnectionTerminated ) ;
321
330
this . _conn . on ( 'end' , cb ) ;
322
331
} else {
323
332
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