Skip to content

Commit eed86ba

Browse files
committed
Fix hanging thread issue by replacing parallel file discovery with sequential
- Replace ignore crate's build_parallel().run() with sequential builder.build() - The parallel walker doesn't guarantee thread completion before returning - Sequential discovery followed by parallel processing with rayon is more reliable - Eliminates the hanging thread issue that prevented app termination - Maintains performance through parallel file processing
1 parent b7f2c81 commit eed86ba

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

crates/scanner-core/src/lib.rs

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -803,57 +803,43 @@ impl<'a> Scanner<'a> {
803803
builder.threads(n.get());
804804
}
805805

806-
let out: Arc<Mutex<Vec<PathBuf>>> = Arc::new(Mutex::new(Vec::with_capacity(4096)));
807-
let out_ref = out.clone();
808-
809-
builder.build_parallel().run(|| {
810-
let out = out_ref.clone();
811-
Box::new(move |res| {
812-
let entry = match res {
813-
Ok(e) => e,
814-
Err(_) => return ignore::WalkState::Continue,
815-
};
806+
// Use sequential walker to collect all paths (this guarantees completion)
807+
let mut discovered_paths = Vec::new();
808+
809+
for result in builder.build() {
810+
let entry = match result {
811+
Ok(e) => e,
812+
Err(_) => continue,
813+
};
816814

817-
if let Some(ft) = entry.file_type() {
818-
if !ft.is_file() {
819-
return ignore::WalkState::Continue;
820-
}
821-
} else if let Ok(md) = entry.metadata() {
822-
if !md.is_file() {
823-
return ignore::WalkState::Continue;
824-
}
825-
} else {
826-
return ignore::WalkState::Continue;
815+
if let Some(ft) = entry.file_type() {
816+
if !ft.is_file() {
817+
continue;
827818
}
828-
829-
let path = entry.into_path();
830-
if !path_allowed(&path) {
831-
return ignore::WalkState::Continue;
819+
} else if let Ok(md) = entry.metadata() {
820+
if !md.is_file() {
821+
continue;
832822
}
823+
} else {
824+
continue;
825+
}
833826

834-
if let Ok(md) = fs::metadata(&path) {
835-
if (md.len() as usize) > self.config.max_file_size {
836-
return ignore::WalkState::Continue;
837-
}
838-
} else {
839-
return ignore::WalkState::Continue;
840-
}
827+
let path = entry.into_path();
828+
if !path_allowed(&path) {
829+
continue;
830+
}
841831

842-
if let Ok(mut guard) = out.lock() {
843-
guard.push(path);
832+
if let Ok(md) = fs::metadata(&path) {
833+
if (md.len() as usize) > self.config.max_file_size {
834+
continue;
844835
}
836+
} else {
837+
continue;
838+
}
845839

846-
ignore::WalkState::Continue
847-
})
848-
});
840+
discovered_paths.push(path);
841+
}
849842

850-
let drained: Vec<PathBuf> = {
851-
match out.lock() {
852-
Ok(mut guard) => guard.drain(..).collect(),
853-
Err(_) => Vec::new(),
854-
}
855-
};
856-
discovered_paths.extend(drained);
857843
discovered_paths
858844
}
859845

0 commit comments

Comments
 (0)