Skip to main content

max / makenotwork

server: run scan-spool disk stats on the blocking pool scan_health_json called fs2::available_space and std::fs::read_dir directly on the async runtime; a slow or large spool directory would stall every other task on the worker thread. Move both onto spawn_blocking. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author: Max Johnson <me@maxj.phd> · 2026-07-02 22:06 UTC
Commit: a135b29e04d37d67498c5f90954097dc5478938e
Parent: a8bd6eb
1 file changed, +18 insertions, -9 deletions
@@ -606,16 +606,25 @@ pub(super) async fn scan_health_json(
606 606 }
607 607 }).collect();
608 608
609 - let spool_dir = std::path::Path::new(crate::constants::SCAN_SPOOL_DIR);
610 - let scan_spool_free_bytes = fs2::available_space(if spool_dir.exists() {
611 - spool_dir
612 - } else {
613 - spool_dir.parent().unwrap_or(std::path::Path::new("/"))
614 - })
615 - .unwrap_or(0);
616 - let scan_spool_file_count = std::fs::read_dir(spool_dir)
617 - .map(|rd| rd.flatten().filter(|e| e.file_type().map(|t| t.is_file()).unwrap_or(false)).count() as u64)
609 + // The spool disk stats hit the filesystem (statvfs + a full directory scan);
610 + // run them on the blocking pool so a slow or large spool dir can't stall the
611 + // async runtime for every other task on this worker thread.
612 + let spool_dir_path = std::path::PathBuf::from(crate::constants::SCAN_SPOOL_DIR);
613 + let (scan_spool_free_bytes, scan_spool_file_count) = tokio::task::spawn_blocking(move || {
614 + let spool_dir = spool_dir_path.as_path();
615 + let free = fs2::available_space(if spool_dir.exists() {
616 + spool_dir
617 + } else {
618 + spool_dir.parent().unwrap_or_else(|| std::path::Path::new("/"))
619 + })
618 620 .unwrap_or(0);
621 + let count = std::fs::read_dir(spool_dir)
622 + .map(|rd| rd.flatten().filter(|e| e.file_type().map(|t| t.is_file()).unwrap_or(false)).count() as u64)
623 + .unwrap_or(0);
624 + (free, count)
625 + })
626 + .await
627 + .unwrap_or((0, 0));
619 628
620 629 let body = ScanPipelineHealth {
621 630 queue_pending,