Repository navigation
fix(extension-core): report a refused retry at the deadline as a transport failure - #6201
matthewgrossman wants to merge 8 commits into
Conversation
…sport failure Bound each retry by the deadline, or the fixed window when there is none, in a single loop, and abandon it with the earlier transport failure. The first attempt stays the caller's to cut short. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
cb6855b to
9ca5747
Compare
The backoff wakes in time, but the refusal arrives after the deadline, so the caller's timeout would otherwise win the race. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
…e deadline The doc comment promises no attempt starts after the deadline, but a backoff that woke at or after it still started one. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
Replace call_with_retries with call_before, which bounds every attempt by the deadline itself and returns Elapsed only for a first attempt that runs out of time. Callers no longer wrap it in a second timeout_at at the same instant, so the result no longer depends on which timer is polled first. The fail-open choice moves in as Unprocessed::Fail, the deadline is required, and the fixed retry window is gone. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
Out of scope for the flake fix in #6196. The one-file fix before it covers both races; the wider restructure can be proposed separately. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
Run each retry under timeout_at(give_up) in a single loop, with a strict pre-sleep bound, so a retry that overruns the deadline reports the failure before it instead of racing the caller's timeout. Drop the overlapping latency sweep test. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
137137137
left a comment
There was a problem hiding this comment.
Tested on macOS arm64 at b15c1be. cargo test -p openshell-extension-core --lib transport passes. "Without the fix" below is this tree with the retry_until call replaced by call().await.
Two cases behave differently from the description.
1. A retry the service accepted is reported as refused (transport.rs:229)
retry_until cannot tell a retry that is still connecting from one the service is already handling. Paused-clock probe: 500 ms deadline, first attempt refused, second attempt sleeps 10 s then answers.
- This PR:
attempts=2 result=Ok(Err(Status { code: Unknown, message: "connect failure", source: Some(Custom { kind: ConnectionRefused, .. }) })) - Without the fix:
attempts=2 result=Err(Elapsed(()))
So a service that restarts and then hangs is reported as unreachable while a request is in flight. The description says a slow service is still reported as a timeout; that holds only for the first attempt.
2. Calls without a deadline are cut at the 5 s window (transport.rs:222-223)
Probe: call_with_retries(None, ..), first attempt refused, retry answers after 6 s.
- This PR:
elapsed=5s result=Err(.. "connect failure" ..) - Without the fix:
elapsed=6.005s result=Ok("answer")
The description says calls without a deadline are unchanged. Should the retry be bounded only when deadline is Some?
| status = match tokio::time::timeout_at(give_up, call()).await { | ||
| Ok(Ok(response)) => return Ok(response), | ||
| Ok(Err(status)) => status, | ||
| Err(_) => break, |
There was a problem hiding this comment.
🤖 review:
Minor: This also changes the outcome for a retry that did connect. Example with a 500 ms fail-closed stage while the service restarts: the attempt at 0 ms is refused, the retry at 5 ms reaches the new instance, and its handler takes 600 ms. At 500 ms the retry is dropped here and the 0 ms refusal is returned.
call_before_deadlinethen yieldsOk(Err(status)), so the chain reports the unavailable reason instead ofStageTimeout/ChainTimeout, and the gateway reports the connect failure instead of "evaluation timed out".
The request is still denied either way, but this is the "slow service" case the description says should stay a timeout, and the returned status says the call was not processed when the service did receive it.
There was a problem hiding this comment.
Good catch, and you're right: dropping a retry that had connected and was slow reported it as the earlier refusal. I've changed the approach. The retry is no longer wrapped in a timeout. Instead a retry starts only if at least the pause it just waited remains before the deadline, so every retry that starts runs to completion and reports what happened. A retry that connects and hangs is a timeout again, like a first attempt. a_retry_that_hangs_is_left_to_the_caller covers it, and it fails on the previous version.
Drop the per-retry timeout_at. A retry now starts only when at least the pause it waited remains before the deadline, so every retry runs to completion and reports what happened: a refusal is a transport failure, and a retry that connected and hangs is a timeout, as for a first attempt. Calls without a deadline are no longer cut at the fixed window. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
|
@137137137 Both points are right and both are fixed by not starting a retry without headroom, instead of cutting retries off with a timeout.
The trade-off is that this is a margin, not a proof: a refusal has to arrive within the headroom, 5 to 100 ms against the few ms the flake needed. The PR description now says so. |
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
|
Re-ran both probes at f5111d0. The slow retry with a 500 ms deadline now gives |
Summary
A fail-closed middleware or gateway interceptor calls its service and sends the call again while the service refuses connections. When the service stays down, the caller should see "unavailable" with the transport failure. Instead it was sometimes reported as "timed out", depending on how long the last refused attempt took to come back. This is what makes the two tests in #6196 flaky on macOS runners.
Example, with a 356 ms deadline and a service that refuses every connection:
Behavior
A retry now starts only if it has room to answer before the deadline. Every retry that starts runs to completion and reports what happened.
A slow service is a timeout, and a service that keeps refusing is a transport failure. The last retry no longer starts so late that its refusal can lose the race against the caller's timeout.
Related Issue
Closes #6196
Changes
call_with_retriesstarts a retry only if at least the pause it just waited remains before the deadline (now + 2 * pause <= give_up). With the 356 ms deadline above, the 355 ms retry is not started, and the 255 ms retry keeps about 100 ms to answer.Testing
cargo nextestforopenshell-extension-core,openshell-gateway-interceptors, andopenshell-supervisor-middlewarepass; fmt and clippy cleantaskpolicy -b,-j 4): 4/300 failures before (same errors as CI), 0/600 after (300 iterations of both tests on the final code)Checklist