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 @@ -276,6 +276,7 @@ class NodeChannel {
276276 } ) ;
277277
278278 self . _conn . on ( 'error' , self . _handleConnectionError ) ;
279+ self . _conn . on ( 'end' , self . _handleConnectionTerminated ) ;
279280
280281 // Drain all pending messages
281282 let pending = self . _pending ;
@@ -293,6 +294,13 @@ class NodeChannel {
293294 }
294295 }
295296
297+ _handleConnectionTerminated ( ) {
298+ this . _error = new Error ( 'Connection was closed by server' ) ;
299+ if ( this . onerror ) {
300+ this . onerror ( this . _error ) ;
301+ }
302+ }
303+
296304 /**
297305 * Write the passed in buffer to connection
298306 * @param {NodeBuffer } buffer - Buffer to write
@@ -318,6 +326,7 @@ class NodeChannel {
318326 this . _open = false ;
319327 if ( this . _conn ) {
320328 this . _conn . end ( ) ;
329+ this . _conn . removeListener ( 'end' , this . _handleConnectionTerminated ) ;
321330 this . _conn . on ( 'end' , cb ) ;
322331 } else {
323332 cb ( ) ;
Original file line number Diff line number Diff line change @@ -40,11 +40,16 @@ class Pool {
4040 }
4141
4242 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+ }
4750 }
51+
52+ return this . _create ( this . _release ) ;
4853 }
4954
5055 _release ( resource ) {
You can’t perform that action at this time.
0 commit comments