Skip to content

Commit 84a3302

Browse files
authored
fix: connection issues after system suspend on Linux (#1626)
Using `Instant::now()` for `is_expired` doesn't account for time spent suspended on Linux as it internally uses `CLOCK_MONOTONIC`. Using `SystemTime::now()` instead (adjusting `timestamp` to `SystemTime` accordingly) fixes this. Although `SystemTime` could go backwards (e.g. due to NTP updates), expiration deals with external systems and thus this should be a non-local time anyhow. Fixes #1617
1 parent a9122dc commit 84a3302

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- [connect] Fixed failed transferring with transfer data that had an empty context uri and no tracks
3030
- [connect] Use the provided index or the first as fallback value to always play a track on loading
3131
- [core] Fixed a problem where the metadata didn't include the audio file by switching to `get_extended_metadata`
32+
- [core] Fixed connection issues after system suspend on Linux
3233

3334
### Removed
3435

core/src/login5.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use librespot_protocol::{
1616
};
1717
use protobuf::well_known_types::duration::Duration as ProtoDuration;
1818
use protobuf::{Message, MessageField};
19-
use std::time::{Duration, Instant};
19+
use std::time::{Duration, SystemTime};
2020
use thiserror::Error;
2121
use tokio::time::sleep;
2222

@@ -264,7 +264,7 @@ impl Login5Manager {
264264
expires_in: Duration::from_secs(expires_in.try_into().unwrap_or(3600)),
265265
token_type: "Bearer".to_string(),
266266
scopes: vec![],
267-
timestamp: Instant::now(),
267+
timestamp: SystemTime::now(),
268268
}
269269
}
270270
}

core/src/spclient.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
fmt::Write,
3-
time::{Duration, Instant},
3+
time::{Duration, SystemTime},
44
};
55

66
use crate::config::{OS, os_version};
@@ -364,7 +364,7 @@ impl SpClient {
364364
.iter()
365365
.map(|d| d.domain.clone())
366366
.collect(),
367-
timestamp: Instant::now(),
367+
timestamp: SystemTime::now(),
368368
};
369369

370370
inner.client_token = Some(client_token);

core/src/token.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// user-library-modify, user-library-read, user-follow-modify, user-follow-read, streaming,
99
// app-remote-control
1010

11-
use std::time::{Duration, Instant};
11+
use std::time::{Duration, SystemTime};
1212

1313
use serde::Deserialize;
1414
use thiserror::Error;
@@ -39,7 +39,7 @@ pub struct Token {
3939
pub expires_in: Duration,
4040
pub token_type: String,
4141
pub scopes: Vec<String>,
42-
pub timestamp: Instant,
42+
pub timestamp: SystemTime,
4343
}
4444

4545
#[derive(Deserialize)]
@@ -115,12 +115,12 @@ impl Token {
115115
expires_in: Duration::from_secs(data.expires_in),
116116
token_type: data.token_type,
117117
scopes: data.scope,
118-
timestamp: Instant::now(),
118+
timestamp: SystemTime::now(),
119119
})
120120
}
121121

122122
pub fn is_expired(&self) -> bool {
123-
self.timestamp + (self.expires_in.saturating_sub(Self::EXPIRY_THRESHOLD)) < Instant::now()
123+
self.timestamp + self.expires_in.saturating_sub(Self::EXPIRY_THRESHOLD) < SystemTime::now()
124124
}
125125

126126
pub fn in_scope(&self, scope: &str) -> bool {

0 commit comments

Comments
 (0)