diff --git a/docs/network/index.html b/docs/network/index.html
index c98ced3a..9bdf520a 100644
--- a/docs/network/index.html
+++ b/docs/network/index.html
@@ -611,13 +611,18 @@ var locales = {
findNode(
- String nodeId)
+ String/Number nodeId)
|
| Returns: Array |
Nodes can be in clusters. Clusters can also be in clusters. This function returns and array of
- nodeIds
- showing where the node is.
Example:
+ nodeIds showing where the node is.
+
+
+ If any nodeId in the chain, especially the first passed in as a parameter, is not present in
+ the current nodes list, an empty array is returned.
+
+
Example:
cluster 'A' contains cluster 'B',
cluster 'B' contains cluster 'C',
cluster 'C' contains node 'fred'.
diff --git a/lib/network/modules/Clustering.js b/lib/network/modules/Clustering.js
index b039a0fc..f295c162 100644
--- a/lib/network/modules/Clustering.js
+++ b/lib/network/modules/Clustering.js
@@ -689,22 +689,32 @@ class ClusterEngine {
/**
* Get the stack clusterId's that a certain node resides in. cluster A -> cluster B -> cluster C -> node
- * @param nodeId
+ *
+ * If a node can't be found in the chain, return an empty array.
+ *
+ * @param {string|number} nodeId
* @returns {Array}
*/
findNode(nodeId) {
let stack = [];
let max = 100;
let counter = 0;
+ let node;
while (this.clusteredNodes[nodeId] !== undefined && counter < max) {
- stack.push(this.body.nodes[nodeId].id);
+ node = this.body.nodes[nodeId]
+ if (node === undefined) return [];
+ stack.push(node.id);
+
nodeId = this.clusteredNodes[nodeId].clusterId;
counter++;
}
- stack.push(this.body.nodes[nodeId].id);
- stack.reverse();
+ node = this.body.nodes[nodeId]
+ if (node === undefined) return [];
+ stack.push(node.id);
+
+ stack.reverse();
return stack;
}
|