Skip to content

fix(api): Add api timeout relaxation and refresh token retry ability#121

Merged
pthurlow merged 1 commit into
mainfrom
fix/retry-api-token
Jun 2, 2026
Merged

fix(api): Add api timeout relaxation and refresh token retry ability#121
pthurlow merged 1 commit into
mainfrom
fix/retry-api-token

Conversation

@pthurlow
Copy link
Copy Markdown
Collaborator

@pthurlow pthurlow commented Jun 2, 2026

Fix upload api bugs when long running uploads trigger token refresh. fixes issue #120

@sentry
Copy link
Copy Markdown

sentry Bot commented Jun 2, 2026

Codecov Report

❌ Patch coverage is 79.49791% with 49 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/api.rs 79.49% 49 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread src/api.rs
Comment on lines +290 to +300
fn send_with_retry(
&self,
build: impl Fn() -> reqwest::blocking::RequestBuilder,
body_for_log: Option<&serde_json::Value>,
) -> (reqwest::StatusCode, String) {
let (status, body) = self.send(build(), body_for_log);
if status == reqwest::StatusCode::UNAUTHORIZED && self.refresh_token() {
return self.send(build(), body_for_log);
}
(status, body)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: (not blocking) On the rayon-parallel paths in indexes.rs, a cloned ApiClient is shared across workers. If the token expires during the parallel iteration, every worker that 401s will independently call (self.refresh)() — each one round-trips to /o/token/ and races on save_session's truncate+write of ~/.hotdata/session.json. Worst case is just wasted refreshes and the last writer winning (POSIX small-write atomicity usually saves the file), but you could collapse the herd by serializing refreshes behind the token mutex (e.g. capture the bearer before sending, then on 401 lock + compare-and-swap so only the first thread refreshes).

@pthurlow pthurlow merged commit 630c591 into main Jun 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant