File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,17 @@ class ConnectionPool extends BaseConnectionPool {
6666 const { id } = connection
6767 debug ( `Marking as 'dead' connection '${ id } '` )
6868 if ( this . dead . indexOf ( id ) === - 1 ) {
69- this . dead . push ( id )
69+ // It might happen that `markDead` is called jsut after
70+ // a pool update, and in such case we will add to the dead
71+ // list a node that no longer exist. The following check verify
72+ // that the connection is still part of the pool before
73+ // marking it as dead.
74+ for ( var i = 0 ; i < this . size ; i ++ ) {
75+ if ( this . connections [ i ] . id === id ) {
76+ this . dead . push ( id )
77+ break
78+ }
79+ }
7080 }
7181 connection . status = Connection . statuses . DEAD
7282 connection . deadCount ++
Original file line number Diff line number Diff line change @@ -74,6 +74,14 @@ test('API', t => {
7474 } , 10 )
7575 } )
7676
77+ t . test ( 'markDead should ignore connections that no longer exists' , t => {
78+ const pool = new ConnectionPool ( { Connection, sniffEnabled : true } )
79+ pool . addConnection ( 'http://localhost:9200/' )
80+ pool . markDead ( { id : 'foo-bar' } )
81+ t . deepEqual ( pool . dead , [ ] )
82+ t . end ( )
83+ } )
84+
7785 t . test ( 'markAlive' , t => {
7886 const pool = new ConnectionPool ( { Connection, sniffEnabled : true } )
7987 const href = 'http://localhost:9200/'
You can’t perform that action at this time.
0 commit comments