Client reconnects about once per second while pending approval (backoff reset on Pending) #285

Closed
opened 2026-11-16 13:20:49 +00:00 by vivy · 2 comments
Owner

Found while setting up a campus client (board GRI-2146), on dev at a61eed0.

What happens

A device that waits for admin approval reconnects about once per second, for as long as it is pending. It never slows down. With one PC that does not matter. With a campus full of new PCs waiting for approval at the same time, it is a steady load on the server.

Cause (from reading the code)

Sync::run in crates/client/src/sync.rs resets the backoff when a connection ends Closed { admitted: true }. admitted is set as soon as the server answers the hello, and a Pending answer counts (HelloOutcome::Pending => AfterHello::Continue in session.rs). So every pending connection that the server closes resets the backoff to BACKOFF_BASE (1 s), and the next delay is about 0.5 to 1 s, every time.

Fix

  • Reset the backoff only when the device is accepted, not when it is pending. Or treat a pending close like Ended::WaitLong, with a fixed, jittered wait.
  • Keep the wait short enough that an approval in the panel still shows on the screen quickly. The server already pushes EnrolmentUpdate on an open connection, so a long-lived pending connection could be better than reconnecting at all.
  • A test: a sequence of pending closes gives growing delays.
Found while setting up a campus client (board GRI-2146), on `dev` at `a61eed0`. ## What happens A device that waits for admin approval reconnects about once per second, for as long as it is pending. It never slows down. With one PC that does not matter. With a campus full of new PCs waiting for approval at the same time, it is a steady load on the server. ## Cause (from reading the code) `Sync::run` in `crates/client/src/sync.rs` resets the backoff when a connection ends `Closed { admitted: true }`. `admitted` is set as soon as the server answers the hello, and a **Pending** answer counts (`HelloOutcome::Pending => AfterHello::Continue` in `session.rs`). So every pending connection that the server closes resets the backoff to `BACKOFF_BASE` (1 s), and the next delay is about 0.5 to 1 s, every time. ## Fix - Reset the backoff only when the device is **accepted**, not when it is pending. Or treat a pending close like `Ended::WaitLong`, with a fixed, jittered wait. - Keep the wait short enough that an approval in the panel still shows on the screen quickly. The server already pushes `EnrolmentUpdate` on an open connection, so a long-lived pending connection could be better than reconnecting at all. - A test: a sequence of pending closes gives growing delays.
Member

Fix pushed: PR #286 (fix/GRI-2149-backoff-reset-on-pending), commit 89e66a6.

Session now tracks admitted itself — true on HelloOutcome::Accepted or on a mid-connection EnrolmentUpdate::Approved, false on a bare Pending hello. Sync::connect_once reads session.is_admitted() instead of hard-coding true, so a still-pending device's backoff keeps growing between reconnects instead of resetting to ~1s every time.

Added unit tests in session.rs covering pending/accepted/mid-connection-approval. cargo test -p client (98 unit + 3 integration tests) and scripts/local-gates.sh --rust-only both pass locally. Waiting on forge CI now.

Fix pushed: PR #286 (fix/GRI-2149-backoff-reset-on-pending), commit 89e66a6. `Session` now tracks `admitted` itself — true on `HelloOutcome::Accepted` or on a mid-connection `EnrolmentUpdate::Approved`, false on a bare `Pending` hello. `Sync::connect_once` reads `session.is_admitted()` instead of hard-coding `true`, so a still-pending device's backoff keeps growing between reconnects instead of resetting to ~1s every time. Added unit tests in `session.rs` covering pending/accepted/mid-connection-approval. `cargo test -p client` (98 unit + 3 integration tests) and `scripts/local-gates.sh --rust-only` both pass locally. Waiting on forge CI now.
Member

CI is green on PR #286 (commit 89e66a67): CI/clippy/deny/fmt/test/frontend/boundary/pre-push all passed. PR is open and mergeable onto dev, no conflicts. Ready for review and merge.

CI is green on PR #286 (commit 89e66a67): CI/clippy/deny/fmt/test/frontend/boundary/pre-push all passed. PR is open and mergeable onto dev, no conflicts. Ready for review and merge.
vivy closed this issue 2026-11-16 14:06:21 +00:00
Sign in to join this conversation.
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage#285
No description provided.