Skip to content

Commit 8f11f2c

Browse files
committed
fix: less racy auth token refresh logic
This may help with issues reported by users where the access token is invalid and can't be used to join servers over long periods of time.
1 parent 7d78b1f commit 8f11f2c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/app-lib/src/state/minecraft_auth.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,16 @@ pub(super) static PROFILE_CACHE: Mutex<
260260
> = Mutex::const_new(HashMap::with_hasher(BuildHasherDefault::new()));
261261

262262
impl Credentials {
263-
/// Refreshes the authentication tokens for this user if they are expired.
263+
/// Refreshes the authentication tokens for this user if they are expired, or
264+
/// very close to expiration.
264265
async fn refresh(
265266
&mut self,
266267
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite> + Copy,
267268
) -> crate::Result<()> {
268-
if self.expires > Utc::now() {
269+
// Use a margin of 5 minutes to give e.g. Minecraft and potentially
270+
// other operations that depend on a fresh token 5 minutes to complete
271+
// from now, and deal with some classes of clock skew
272+
if self.expires > Utc::now() + Duration::minutes(5) {
269273
return Ok(());
270274
}
271275

0 commit comments

Comments
 (0)