From 686a521c3e25d71895a8396f7e5962edd610dafe Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Sun, 19 Apr 2026 15:12:07 +0800 Subject: [PATCH] don't panic when sending error response to disconnected client If handle_request fails after the client has disconnected (for example a client timeout while the agent was still waiting on pinentry), the unwrap in the error-reporting path panics the tokio task and drops the socket. The client then reads EOF from the socket and reports an unhelpful "failed to parse message from agent: EOF while parsing a value at line 1 column 0", hiding the original error. Log the send failure as a warning instead. --- src/bin/rbw-agent/agent.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bin/rbw-agent/agent.rs b/src/bin/rbw-agent/agent.rs index 1691ed51..18c5844b 100644 --- a/src/bin/rbw-agent/agent.rs +++ b/src/bin/rbw-agent/agent.rs @@ -74,12 +74,19 @@ impl Agent { let res = handle_request(&mut sock, state.clone()).await; if let Err(e) = res { - // unwrap is the only option here - sock.send(&rbw::protocol::Response::Error { - error: format!("{e:#}"), - }) - .await - .unwrap(); + // the client may have disconnected already, so + // we can't do anything useful with a send + // failure; just log it instead of panicking + if let Err(send_err) = sock + .send(&rbw::protocol::Response::Error { + error: format!("{e:#}"), + }) + .await + { + log::warn!( + "failed to send error response to client: {send_err:#}" + ); + } } }); }