Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent infinite loop in health check when there is no progress #4372

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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