Repository navigation
fix(client-runtime): slow foreground probes keep live sessions connected #24309
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
Changes from all commits
d680ed1
fb1ceaf
9173f32
012a799
3eaf43f
dccda35
a5e94ad
f382f90
cce32aa
a5a03cc
35d2dea
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 |
|---|---|---|
|
|
@@ -691,6 +691,9 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( | |
| } | ||
| }; | ||
|
|
||
| const isForegroundProbe = (next: SupervisorSignal) => | ||
| next._tag === "Wakeup" && next.reason === "application-active"; | ||
|
|
||
| // Ends "silent" when the host answers a fresh request while the socket | ||
| // delivers nothing, as when iOS kills a suspended socket without a close | ||
| // event, and "alive" once the socket delivers a frame. A slow or | ||
|
|
@@ -772,7 +775,11 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( | |
| continue; | ||
| } | ||
| yield* Ref.set(probeUnanswered, true); | ||
| const probe = yield* Effect.forkChild(lease.session.probe); | ||
| let probe = yield* Effect.forkChild(lease.session.probe); | ||
| // A busy server can miss one foreground probe while the socket is still | ||
| // healthy, so the first miss asks again and only the follow-up's miss | ||
| // replaces the session. | ||
| let toleratesMiss = isForegroundProbe(next); | ||
| let silentSocket: Fiber.Fiber<"silent" | "alive"> | undefined; | ||
| // A signal during a running check, such as a network change that kills | ||
| // the socket, needs a fresh check only if the running one sees a frame. | ||
|
|
@@ -785,7 +792,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( | |
| // The web and desktop foreground probe allows a busy host 15 seconds, | ||
| // and a busy host can answer a fresh request before a queued probe. | ||
| const armSilentSocketCheck = Effect.fnUntraced(function* (signal: SupervisorSignal) { | ||
| if (signal._tag === "Wakeup" && signal.reason === "application-active") return; | ||
| if (isForegroundProbe(signal)) return; | ||
| if (silentSocket !== undefined) { | ||
| recheck = true; | ||
| return; | ||
|
|
@@ -837,6 +844,13 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( | |
| return true; | ||
| } | ||
| if (probeEvent._tag === "TimedOut") { | ||
| if (toleratesMiss) { | ||
| toleratesMiss = false; | ||
| yield* Fiber.interrupt(probe); | ||
| probe = yield* Effect.forkChild(lease.session.probe); | ||
| deadline = (yield* Clock.monotonicTimeNanos) + Duration.toNanosUnsafe(probeTimeout); | ||
| continue; | ||
| } | ||
| yield* stopProbe; | ||
| // A long suspension leaves the socket suspect even when the network | ||
| // reports offline, so it is replaced like a silent one. | ||
|
|
@@ -861,6 +875,9 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( | |
| } | ||
| const signalTimeout = probeTimeoutFor(probeEvent.signal, routeKind); | ||
| if (signalTimeout !== undefined) { | ||
| // A retry or network signal wants a definite answer, even when its | ||
| // own deadline lands after the foreground one. | ||
| if (!isForegroundProbe(probeEvent.signal)) toleratesMiss = false; | ||
|
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. 🎯 Functional Correctness | 🔎 Supported by static analysis
Clear tolerated misses for every While a foreground probe is stalled, an Handle 🐛 Suggested fix
|
||
| if (isLongResume(probeEvent.signal) && !longResume) { | ||
| longResume = true; | ||
| longResumeStartedAt = yield* Clock.monotonicTimeNanos; | ||
|
|
||
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.
Script executed:
Repository: pingdotgg/t3code
Length of output: 11948
Script executed:
Repository: pingdotgg/t3code
Length of output: 42855
Script executed:
Repository: pingdotgg/t3code
Length of output: 38330
Preserve offline reports for the probe policy
If a primary target is already projected as unknown, an offline report during a foreground probe is suppressed. An unanswered probe can then start the follow-up instead of using strict offline recovery, delaying replacement by up to another 15 seconds.
Forward the offline report to the probe policy even when the primary projection is unchanged, while keeping the primary target exempt from the offline gate.