Repository navigation
remote: fix metadata refresher lifetime and stale token recovery - #138
Merged
Merged
Conversation
* `Remote` derives `Clone` and all clones share one metadata refresh task, but the `Drop` impl aborted that task on every clone drop. `watch()` captures a clone in its stream, so dropping a watch stream permanently killed the refresher for the whole database: the data path then reused the last token forever and every call failed with an auth error once the token expired. The abort now lives in a guard owned by the `Arc`, so it fires only when the last clone is dropped. * The data path no longer sends tokens that are known to be expired: `call_raw` checks `expires_at` and forces an immediate metadata refresh first. The refresh task wakes on demand via `Notify` instead of only on its timer. * On an auth-failure response (400/401/403), force a metadata refresh and retry once before surfacing the error, so a token that the server considers stale heals transparently instead of failing user calls.
Review feedback: * A 400 response triggers the forced-refresh retry only when the response body mentions the authorization header, so genuinely malformed requests (e.g. an invalid atomic_write) are not replayed. 401/403 still retry unconditionally. * Add a test covering the expiry pre-flight: already-expired metadata with a wedged refresh fetch must force a refresh attempt, wait out the bounded timeout, and fall back to the held token instead of hanging or failing. * Document the benign redundant fetch that occurs when a forced refresh lands while a metadata fetch is already in flight.
piscisaureus
force-pushed
the
fix-metadata-refresher
branch
from
June 6, 2026 07:34
16d4e11 to
c32f7ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #137.
RemotederivesCloneand all clones share one metadata refreshtask via
Arc<JoinHandle>, but theDropimpl aborted that task onevery clone drop.
watch()captures a clone in its stream, sodropping a watch stream permanently killed the refresher for the
whole database handle: the data path then reused the last token
forever and, once it expired, every call failed with an auth error
until the process restarted. The abort is moved into a
MetadataRefresherguard owned by theArc, so it fires only whenthe last clone is dropped.
call_rawchecksexpires_atbefore use and forces an immediatemetadata refresh (bounded wait) first. The refresh task wakes on
demand via
Notifyinstead of only on its timer, and wakes forced-refresh waiters even when a fetch attempt fails.
a metadata refresh and retry once before surfacing the error, so a
token the server considers stale (e.g. due to clock leeway past
expiresAt) heals transparently.New tests in
remote/tests/refresh.rsuse a mock transport withcontrollable token rotation; the clone-drop, watch-drop, and
auth-retry tests fail against the previous implementation.