Skip to content

Commit

Permalink
fix: prevent infinite loop in health check when there is no progress (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Mar 15, 2022
1 parent 117b2ef commit 44ea4aa
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/zwave-js/src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3845,7 +3845,10 @@ protocol version: ${this.protocolVersion}`;
? 5000
: 1000;

// Track how often we failed to get a response from the node, so we can abort if the connection is too bad
let continuousErrors = 0;
// Also track how many times in a row there was no progress, which also indicates a bad connection
let previousProgress = 0;
while (true) {
// The node might send an unsolicited update when it finishes the test
const report = await this.driver
Expand All @@ -3862,13 +3865,18 @@ protocol version: ${this.protocolVersion}`;
: // If it didn't come in the wait time, poll for an update
await api.getNodeTestStatus().catch(() => undefined);

// If we didn't get a result, try again next iteration
if (!status) {
// Safeguard against infinite loop
// Safeguard against infinite loop:
// If we didn't get a result, or there was no progress, try again next iteration
if (
!status ||
(status.status === PowerlevelTestStatus["In Progress"] &&
status.acknowledgedFrames === previousProgress)
) {
if (continuousErrors > 5) return result(0);
continuousErrors++;
continue;
} else {
previousProgress = status.acknowledgedFrames;
continuousErrors = 0;
}

Expand Down

0 comments on commit 44ea4aa

Please sign in to comment.