diff --git a/src/ipc.rs b/src/ipc.rs index 9b999a4..69ff64d 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -1,6 +1,6 @@ //! Local IPC protocol and client for the Appa daemon. -use std::{io, path::PathBuf}; +use std::{io, path::PathBuf, time::Duration}; use anyhow::Context; use serde::{Deserialize, Serialize}; @@ -16,6 +16,7 @@ use crate::{ pub const PROTOCOL_VERSION: u16 = 1; const MAX_MESSAGE_BYTES: usize = 1024 * 1024; +const DAEMON_REQUEST_TIMEOUT: Duration = Duration::from_secs(8); #[derive(Debug, Deserialize, Serialize)] pub(crate) struct Request { @@ -209,6 +210,17 @@ impl DaemonClient { } async fn request(&self, command: Command) -> anyhow::Result { + tokio::time::timeout(DAEMON_REQUEST_TIMEOUT, self.request_inner(command)) + .await + .map_err(|_| { + anyhow::anyhow!( + "Appa daemon did not respond within {} seconds", + DAEMON_REQUEST_TIMEOUT.as_secs() + ) + })? + } + + async fn request_inner(&self, command: Command) -> anyhow::Result { let mut stream = UnixStream::connect(&self.socket_path) .await .with_context(|| {