diff --git a/Cargo.lock b/Cargo.lock index ba2693828e..e17e5621fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2890,6 +2890,7 @@ dependencies = [ "futures 0.3.30", "futures-util", "hkdf", + "scopeguard", "sentry", "sentry-backtrace", "serde 1.0.203", diff --git a/syncserver-common/Cargo.toml b/syncserver-common/Cargo.toml index 696bf22ffc..ccca00de62 100644 --- a/syncserver-common/Cargo.toml +++ b/syncserver-common/Cargo.toml @@ -19,3 +19,5 @@ serde_json.workspace = true slog.workspace = true slog-scope.workspace = true hkdf.workspace = true + +scopeguard = "1.2" diff --git a/syncserver-common/src/lib.rs b/syncserver-common/src/lib.rs index 934a4414f7..fce3a8257f 100644 --- a/syncserver-common/src/lib.rs +++ b/syncserver-common/src/lib.rs @@ -121,16 +121,17 @@ impl BlockingThreadpool { E: fmt::Debug + Send + InternalError + 'static, { self.spawned_tasks.fetch_add(1, Ordering::Relaxed); + // Ensure the counter's always decremented (whether the task completed, + // was cancelled or panicked) + scopeguard::defer! { + self.spawned_tasks.fetch_sub(1, Ordering::Relaxed); + } - let result = web::block(f).await.unwrap_or_else(|_| { + web::block(f).await.unwrap_or_else(|_| { Err(E::internal_error( "Blocking threadpool operation canceled".to_owned(), )) - }); - - self.spawned_tasks.fetch_sub(1, Ordering::Relaxed); - - result + }) } pub fn active_threads(&self) -> u64 { diff --git a/syncserver-settings/src/lib.rs b/syncserver-settings/src/lib.rs index 0765dff744..e8bd265b68 100644 --- a/syncserver-settings/src/lib.rs +++ b/syncserver-settings/src/lib.rs @@ -161,7 +161,16 @@ impl Settings { let db = Url::parse(&self.syncstorage.database_url) .map(|url| url.scheme().to_owned()) .unwrap_or_else(|_| "".to_owned()); - format!("http://{}:{} ({}) {}", self.host, self.port, db, quota) + let parallelism = format!( + "available_parallelism: {:?} num_cpus: {} num_cpus (phys): {}", + std::thread::available_parallelism(), + num_cpus::get(), + num_cpus::get_physical() + ); + format!( + "http://{}:{} ({db}) ({parallelism}) {quota}", + self.host, self.port + ) } }