Skip to content

Commit

Permalink
Stage1: fix zombie processes
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Apr 9, 2024
1 parent 343fc51 commit 6deed81
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/stages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub fn stage1(args: &Cli) -> UserVote {
tracing::info!("Processing {}", filename);
// decide whether directly read the file, or use a decompressor
let filetype = deduce_log_file_type(filename);

let mut child_process = None;
let bufreader: BufReader<Box<dyn std::io::Read>> = match filetype {
LogFileType::Plain => {
let file = std::fs::File::open(entry.path()).expect("open file failed");
Expand All @@ -86,7 +88,9 @@ pub fn stage1(args: &Cli) -> UserVote {
.stdout(std::process::Stdio::piped())
.spawn()
.expect("spawn decompressor failed");
std::io::BufReader::new(Box::new(output.stdout.expect("get stdout failed")))
child_process = Some(output);
let stdout = child_process.as_mut().unwrap().stdout.take().expect("get stdout failed");
std::io::BufReader::new(Box::new(stdout))
}
};

Expand Down Expand Up @@ -144,6 +148,11 @@ pub fn stage1(args: &Cli) -> UserVote {
vote.resp_size = vote.resp_size.max(item.size);
access_record.insert(ip_prefix_url, item.time.into());
}

// Reap child processes, if any
if let Some(mut child) = child_process {
let _ = child.wait();
}
}

// Get sorted vote "report".
Expand Down

0 comments on commit 6deed81

Please sign in to comment.