Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: real time pipe stopping

Louis Beaumontaf6d3ce20cb5
diff --git a/screenpipe-server/Cargo.toml b/screenpipe-server/Cargo.toml
index 81ac878db..9a77418b3 100644
--- a/screenpipe-server/Cargo.toml
+++ b/screenpipe-server/Cargo.toml
@@ -162,3 +162,9 @@ path = "src/bin/screenpipe-server.rs"
[package.metadata.cargo-machete]
ignored = ["url", "opentelemetry-appender-tracing"]
+
+[target.'cfg(unix)'.dependencies]
+nix = { version = "0.29", features = ["signal"] }
+
+[target.'cfg(windows)'.dependencies]
+windows = { version = "0.58", features = ["Win32_System_Threading", "Win32_Foundation"] }
diff --git a/screenpipe-server/src/pipe_manager.rs b/screenpipe-server/src/pipe_manager.rs
index 475da5f9d..77f6b991a 100644
--- a/screenpipe-server/src/pipe_manager.rs
+++ b/screenpipe-server/src/pipe_manager.rs
@@ -229,8 +229,29 @@ impl PipeManager {
if let Some(handle) = pipes.remove(id) {
info!("stopping pipe: {} with pid {}", id, handle.pid);
- // Send kill signal through channel
- let _ = handle.kill_tx.send(()).await;
+ // Send kill signal and wait for confirmation
+ handle.kill_tx.send(()).await?;
+
+ // Wait a bit for the process to actually terminate
+ tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
+
+ // Force kill the process if it's still running
+ #[cfg(unix)]
+ {
+ use nix::sys::signal::{kill, Signal};
+ use nix::unistd::Pid;
+ let _ = kill(Pid::from_raw(handle.pid), Signal::SIGKILL);
+ }
+ #[cfg(windows)]
+ {
+ use windows::Win32::System::Threading::{OpenProcess, TerminateProcess};
+ use windows::Win32::Foundation::{HANDLE, BOOL};
+ unsafe {
+ if let Ok(h_process) = OpenProcess(0x0001, false, handle.pid as u32) {
+ let _ = TerminateProcess(h_process, 1);
+ }
+ }
+ }
info!("stopped pipe: {}", id);
}