Repository navigation
fix(client-runtime): an offline connection still tries when the offline report is stale #39223
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
base: main
Are you sure you want to change the base?
Changes from all commits
edd5993
5dce519
90b80bf
eff788c
c47976e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ import { | |
|
|
||
| const RETRY_BASE_DELAY_MS = 1_000; | ||
| const RETRY_MAX_DELAY_MS = 300_000; | ||
| const OFFLINE_RECHECK_MS = 30_000; | ||
| const SESSION_LOSS_RETRY_DELAY_MS = 250; | ||
| // Someone is approving this device on the host; check back soon rather than climbing the ladder. | ||
| const APPROVAL_PENDING_RETRY_DELAY_MS = 4_000; | ||
|
|
@@ -1195,6 +1196,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( | |
| pendingRetry = Option.none(); | ||
| }; | ||
| let replacing = false; | ||
| let offlineRecheckDue = false; | ||
|
|
||
| for (;;) { | ||
| const retryRequested = yield* Ref.getAndSet(resetRetryState, false); | ||
|
|
@@ -1215,15 +1217,18 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( | |
| continue; | ||
| } | ||
| // The platform's offline report can stay wrong after the network is back, | ||
| // so an explicit retry still tries instead of waiting for it to change. | ||
| const ignoreOffline = replacing || retryRequested; | ||
| // so an explicit retry, or every OFFLINE_RECHECK_MS, still tries once. | ||
| const recheck = | ||
| offlineRecheckDue && !replacing && !retryRequested && currentIntent.network === "offline"; | ||
| const ignoreOffline = replacing || retryRequested || recheck; | ||
| if (currentIntent.network === "offline" && !ignoreOffline) { | ||
| yield* clearLease; | ||
| yield* setState(offlineState(currentIntent, generation, failureCount + 1, latestFailure)); | ||
| const applicationActivated = yield* waitForSignal; | ||
| const applicationActivated = yield* waitForRetrySignal(OFFLINE_RECHECK_MS); | ||
| if (applicationActivated) { | ||
| resetRetryLadder(); | ||
| } | ||
| offlineRecheckDue = true; | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -1233,6 +1238,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( | |
| runAttempt(attempt, nextGeneration, latestFailure, pendingRetry, ignoreOffline), | ||
| ); | ||
| replacing = false; | ||
| offlineRecheckDue = false; | ||
| const failedProbe = yield* Ref.getAndSet(probeUnanswered, false); | ||
| if (outcome.established) { | ||
| generation = nextGeneration; | ||
|
|
@@ -1252,6 +1258,10 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( | |
| } | ||
| continue; | ||
| } | ||
| // A failed recheck while still reported offline is not a connection failure. | ||
| if (recheck && !outcome.established && (yield* Ref.get(intent)).network === "offline") { | ||
| continue; | ||
|
Comment on lines
+1262
to
+1263
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve blocked errors from offline rechecks. If a timed recheck returns Handle
|
||
| } | ||
|
|
||
| const attemptSpan: Option.Option<Tracer.Span> = outcome.failure.attemptSpan; | ||
| const error: ConnectionAttemptError = outcome.failure.error; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear the recheck flag on early wakes and when the connection is no longer desired.
waitForRetrySignalreturnsfalseboth when the 30-second timer expires and whenConnectRequested,DisconnectRequested,RetryRequested, orNetworkChangedarrives. Line 1230 setsofflineRecheckDue = truein both cases. A repeatedconnect()during the offline wait therefore starts an attempt immediately, without the 30-second interval. The flag is also not cleared when the connection stops being desired, so a disconnect during the offline wait can cause an immediate attempt on a later connect.Set the flag only when
OFFLINE_RECHECK_MSelapses. The wait must report timer expiry separately from signal wakes. Clear the flag whenever the connection is no longer desired. Explicit Retry must still bypass the offline gate immediately.Suggested fix for the stale flag
if (!currentIntent.desired) { resetRetryLadder(); + offlineRecheckDue = false; latestFailure = null;