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 {
280280 } ) ;
281281
282282 self . _conn . on ( 'error' , self . _handleConnectionError ) ;
283+ self . _conn . on ( 'end' , self . _handleConnectionTerminated ) ;
283284
284285 // Drain all pending messages
285286 let pending = self . _pending ;
@@ -297,6 +298,13 @@ class NodeChannel {
297298 }
298299 }
299300
301+ _handleConnectionTerminated ( ) {
302+ this . _error = new Error ( 'Connection was closed by server' ) ;
303+ if ( this . onerror ) {
304+ this . onerror ( this . _error ) ;
305+ }
306+ }
307+
300308 isEncrypted ( ) {
301309 return this . _encrypted ;
302310 }
@@ -326,6 +334,7 @@ class NodeChannel {
326334 this . _open = false ;
327335 if ( this . _conn ) {
328336 this . _conn . end ( ) ;
337+ this . _conn . removeListener ( 'end' , this . _handleConnectionTerminated ) ;
329338 this . _conn . on ( 'end' , cb ) ;
330339 } else {
331340 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