Skip to content

Commit 02c5b86

Browse files
authored
Skip adding new nodes that aren't ready yet (#1994)
1 parent 63cd655 commit 02c5b86

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

lib/pool/BaseConnectionPool.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ class BaseConnectionPool {
206206

207207
for (let i = 0, len = ids.length; i < len; i++) {
208208
const node = nodes[ids[i]]
209+
210+
// newly-added nodes do not have http assigned yet, so skip
211+
if (node.http === undefined) continue
212+
209213
// If there is no protocol in
210214
// the `publish_address` new URL will throw
211215
// the publish_address can have two forms:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"./*": "./*.js"
1313
},
1414
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
15-
"version": "7.17.12",
16-
"versionCanary": "7.17.12-canary.1",
15+
"version": "7.17.13",
16+
"versionCanary": "7.17.13-canary.1",
1717
"keywords": [
1818
"elasticsearch",
1919
"elastic",

test/unit/base-connection-pool.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,36 @@ test('API', t => {
313313
t.end()
314314
})
315315

316+
t.test('Should skip nodes that do not have an http property yet', t => {
317+
const pool = new BaseConnectionPool({ Connection })
318+
const nodes = {
319+
a1: {
320+
http: {
321+
publish_address: '127.0.0.1:9200'
322+
},
323+
roles: ['master', 'data', 'ingest']
324+
},
325+
a2: {
326+
roles: ['master', 'data', 'ingest']
327+
}
328+
}
329+
330+
t.same(pool.nodesToHost(nodes, 'http:'), [{
331+
url: new URL('http://127.0.0.1:9200'),
332+
id: 'a1',
333+
roles: {
334+
master: true,
335+
data: true,
336+
ingest: true,
337+
ml: false
338+
}
339+
}])
340+
341+
t.equal(pool.nodesToHost(nodes, 'http:').length, 1)
342+
t.equal(pool.nodesToHost(nodes, 'http:')[0].url.host, '127.0.0.1:9200')
343+
t.end()
344+
})
345+
316346
t.end()
317347
})
318348

0 commit comments

Comments
 (0)