Skip to content

Commit

Permalink
Skipping new nodes which do not have the http property present yet.
Browse files Browse the repository at this point in the history
Signed-off-by: Jaco Smit <jacobuss@amazon.com>
  • Loading branch information
jaco-smit committed Feb 25, 2025
1 parent 3988542 commit 2fb7cf3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [3.3.0]
### Changed
- Updated API to match the OpenSearch spec from Feb 11, 2025
### Fixed
- Skip nodes that are not ready ready yet ([#984](https://github.com/opensearch-project/opensearch-js/issues/984))

## [3.2.0]
### Changed
Expand Down
6 changes: 6 additions & 0 deletions lib/pool/BaseConnectionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ class BaseConnectionPool {

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

// New nodes do not have the http property populated yet. Skip this for now.
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
31 changes: 31 additions & 0 deletions test/unit/base-connection-pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,5 +628,36 @@ test('API', (t) => {
}
});

t.test('Should skip nodes when the http property is undefined', (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,
},
},
]);

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();
});

0 comments on commit 2fb7cf3

Please sign in to comment.