max / makenotwork
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, |