fix(api): Add api timeout relaxation and refresh token retry ability#121
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| 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) | ||
| } |
There was a problem hiding this comment.
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).
Fix upload api bugs when long running uploads trigger token refresh. fixes issue #120