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

Add a bit of broker backoff when things go sour. #1134

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/service/synchronize.toit
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,21 @@ class SynchronizeJob extends TaskJob:
assert: runlevel != Job.RUNLEVEL-STOP // Stop does not return.

try:
start := Time.monotonic-us
start-us := Time.monotonic-us
// TODO(kasper): Should the limit be higher in safe mode?
limit := start + TIMEOUT-BROKER-CONNECT.in-us
while not connect-network_ and Time.monotonic-us < limit:
limit-us := start-us + TIMEOUT-BROKER-CONNECT.in-us
backoff-us := 0
while not connect-network_:
// If we didn't manage to connect to the broker, we
// try to connect again. The next time, due to the
// quarantining, we might pick a different network.
logger_.info "connecting to broker failed - retrying"
if Time.monotonic-us + backoff-us >= limit-us: break
backoff := Duration --us=backoff-us
logger_.info "connecting to broker failed - retrying" --tags={"backoff": backoff}
sleep backoff
// Increase the backoff time to avoid aggressively
// connecting to the broker in a busy loop.
backoff-us += Duration.MICROSECONDS-PER-SECOND
finally:
if is-firmware-upgrade-pending_:
exception := catch: firmware.upgrade
Expand Down
Loading