Skip to content

Commit

Permalink
Skip adding new nodes that aren't ready yet (#1994)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMock authored Aug 31, 2023
1 parent 63cd655 commit 02c5b86
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/pool/BaseConnectionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ class BaseConnectionPool {

for (let i = 0, len = ids.length; i < len; i++) {
const node = nodes[ids[i]]

// newly-added nodes do not have http assigned yet, so skip
if (node.http === undefined) continue

// If there is no protocol in
// the `publish_address` new URL will throw
// the publish_address can have two forms:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"./*": "./*.js"
},
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
"version": "7.17.12",
"versionCanary": "7.17.12-canary.1",
"version": "7.17.13",
"versionCanary": "7.17.13-canary.1",
"keywords": [
"elasticsearch",
"elastic",
Expand Down
30 changes: 30 additions & 0 deletions test/unit/base-connection-pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,36 @@ test('API', t => {
t.end()
})

t.test('Should skip nodes that do not have an http property yet', t => {
const pool = new BaseConnectionPool({ Connection })
const nodes = {
a1: {
http: {
publish_address: '127.0.0.1:9200'
},
roles: ['master', 'data', 'ingest']
},
a2: {
roles: ['master', 'data', 'ingest']
}
}

t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://127.0.0.1:9200'),
id: 'a1',
roles: {
master: true,
data: true,
ingest: true,
ml: false
}
}])

t.equal(pool.nodesToHost(nodes, 'http:').length, 1)
t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, '127.0.0.1:9200')
t.end()
})

t.end()
})

Expand Down

0 comments on commit 02c5b86

Please sign in to comment.