Skip to content

Commit 4259183

Browse files
authored
fix: ensure the pool counter's always decremented via scopeguard (#1604)
also report machine parallelism @ startup Issue SYNC-4421
1 parent e9934b5 commit 4259183

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

syncserver-common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ serde_json.workspace = true
1919
slog.workspace = true
2020
slog-scope.workspace = true
2121
hkdf.workspace = true
22+
23+
scopeguard = "1.2"

syncserver-common/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,17 @@ impl BlockingThreadpool {
121121
E: fmt::Debug + Send + InternalError + 'static,
122122
{
123123
self.spawned_tasks.fetch_add(1, Ordering::Relaxed);
124+
// Ensure the counter's always decremented (whether the task completed,
125+
// was cancelled or panicked)
126+
scopeguard::defer! {
127+
self.spawned_tasks.fetch_sub(1, Ordering::Relaxed);
128+
}
124129

125-
let result = web::block(f).await.unwrap_or_else(|_| {
130+
web::block(f).await.unwrap_or_else(|_| {
126131
Err(E::internal_error(
127132
"Blocking threadpool operation canceled".to_owned(),
128133
))
129-
});
130-
131-
self.spawned_tasks.fetch_sub(1, Ordering::Relaxed);
132-
133-
result
134+
})
134135
}
135136

136137
pub fn active_threads(&self) -> u64 {

syncserver-settings/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ impl Settings {
161161
let db = Url::parse(&self.syncstorage.database_url)
162162
.map(|url| url.scheme().to_owned())
163163
.unwrap_or_else(|_| "<invalid db>".to_owned());
164-
format!("http://{}:{} ({}) {}", self.host, self.port, db, quota)
164+
let parallelism = format!(
165+
"available_parallelism: {:?} num_cpus: {} num_cpus (phys): {}",
166+
std::thread::available_parallelism(),
167+
num_cpus::get(),
168+
num_cpus::get_physical()
169+
);
170+
format!(
171+
"http://{}:{} ({db}) ({parallelism}) {quota}",
172+
self.host, self.port
173+
)
165174
}
166175
}
167176

0 commit comments

Comments
 (0)