Skip to content

Commit 9504826

Browse files
authored
fix: use kill_on_drop() to avoid zombie proc in error case (#887)
In the previous macOS file search implementation, we spawned an mdfind child process and killed it when we got the results we needed to avoid zombie processes. However, this kill step would be skipped if an error happened during query results processing as we propagate errors. This commit replaces the manual kill operation with the `ChildProcHandle.kill_on_drop()` API to let RAII do the job to fix the issue.
1 parent 412c8d8 commit 9504826

File tree

2 files changed

+6
-9
lines changed
  • docs/content.en/docs/release-notes
  • src-tauri/src/extension/built_in/file_search/implementation

2 files changed

+6
-9
lines changed

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Information about release notes of Coco App is provided here.
3333
- fix: shortcut key not opening extension store #877
3434
- fix: set up hotkey on main thread or Windows will complain #879
3535
- fix: resolve deeplink login issue #881
36+
- fix: use kill_on_drop() to avoid zombie proc in error case #887
3637

3738
### ✈️ Improvements
3839

src-tauri/src/extension/built_in/file_search/implementation/macos.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) async fn hits(
2525
size: usize,
2626
config: &FileSearchConfig,
2727
) -> Result<Vec<(Document, f64)>, String> {
28-
let (mut iter, mut mdfind_child_process) =
28+
let (mut iter, _mdfind_child_process) =
2929
execute_mdfind_query(&query_string, from, size, &config)?;
3030

3131
// Convert results to documents
@@ -73,12 +73,6 @@ pub(crate) async fn hits(
7373

7474
hits.push((doc, SCORE));
7575
}
76-
// Kill the mdfind process once we get the needed results to prevent zombie
77-
// processes.
78-
mdfind_child_process
79-
.kill()
80-
.await
81-
.map_err(|e| format!("{:?}", e))?;
8276

8377
Ok(hits)
8478
}
@@ -130,8 +124,9 @@ fn build_mdfind_query(query_string: &str, config: &FileSearchConfig) -> Vec<Stri
130124
/// # Return value:
131125
///
132126
/// * impl Stream: an async iterator that will yield the matched files
133-
/// * Child: The handle to the mdfind process, we need to kill it once we
134-
/// collect all the results to avoid zombie processes.
127+
/// * Child: The handle to the mdfind process. The child process will be killed
128+
/// when this handle gets dropped, we need to keep it alive until we exhaust
129+
/// all the query results.
135130
fn execute_mdfind_query(
136131
query_string: &str,
137132
from: usize,
@@ -149,6 +144,7 @@ fn execute_mdfind_query(
149144
.args(&args[1..])
150145
.stdout(tx)
151146
.stderr(std::process::Stdio::null())
147+
.kill_on_drop(true)
152148
.spawn()
153149
.map_err(|e| format!("Failed to spawn mdfind: {}", e))?;
154150
let config_clone = config.clone();

0 commit comments

Comments
 (0)