From 106804ec277f986488d52315267603b3a5135c6f Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Wed, 18 Aug 2021 14:14:18 +0200 Subject: [PATCH] fix(find): Hang due to not resetting active status on finished --- plugins/src/files/mod.rs | 2 +- plugins/src/find/mod.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/src/files/mod.rs b/plugins/src/files/mod.rs index 07446fe..01a0c55 100644 --- a/plugins/src/files/mod.rs +++ b/plugins/src/files/mod.rs @@ -180,7 +180,7 @@ impl App { .await; if id == 19 { - break + break; } } diff --git a/plugins/src/find/mod.rs b/plugins/src/find/mod.rs index 41c6eae..5edff63 100644 --- a/plugins/src/find/mod.rs +++ b/plugins/src/find/mod.rs @@ -2,7 +2,7 @@ use futures_lite::*; use pop_launcher::*; use postage::mpsc; use postage::prelude::{Sink, Stream}; -use smol::process::{ChildStdout, Command, Stdio}; +use smol::process::{Child, ChildStdout, Command, Stdio}; use std::borrow::Cow; use std::cell::Cell; use std::io; @@ -148,8 +148,8 @@ impl SearchContext { async fn search(&mut self, search: String) { tracing::debug!("searching for {}", search); - let mut stdout = match query(&search).await { - Ok(stdout) => futures_lite::io::BufReader::new(stdout).lines(), + let (mut child, mut stdout) = match query(&search).await { + Ok((child, stdout)) => (child, futures_lite::io::BufReader::new(stdout).lines()), Err(why) => { tracing::error!("failed to spawn fdfind process: {}", why); self.active.set(false); @@ -189,11 +189,14 @@ impl SearchContext { } crate::send(&mut self.out, PluginResponse::Finished).await; + self.active.set(false); + let _ = child.kill(); + let _ = child.status().await; } } /// Submits the search query to `fdfind`, and returns its stdout pipe. -async fn query(arg: &str) -> io::Result { +async fn query(arg: &str) -> io::Result<(Child, ChildStdout)> { let mut child = Command::new("fdfind") .arg(arg) .stdin(Stdio::null()) @@ -202,7 +205,7 @@ async fn query(arg: &str) -> io::Result { .spawn()?; match child.stdout.take() { - Some(stdout) => Ok(stdout), + Some(stdout) => Ok((child, stdout)), None => Err(io::Error::new( io::ErrorKind::BrokenPipe, "stdout pipe is missing",