From d62a24b66fd1b0e96cc5e09a9be317c32a356c72 Mon Sep 17 00:00:00 2001 From: Ryan Fowler Date: Sun, 1 Feb 2026 07:30:39 -0800 Subject: [PATCH] Catch panics in worker thread to keep connection alive Wrap user-provided closure execution in catch_unwind so that a panic does not kill the worker thread and permanently destroy the connection. The panicked operation still returns Error::Closed, but subsequent operations continue to work. --- src/client.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index 0886ca5..23f5c75 100644 --- a/src/client.rs +++ b/src/client.rs @@ -153,7 +153,11 @@ impl Client { while let Ok(cmd) = conn_rx.recv() { match cmd { - Command::Func(func) => func(&mut conn), + Command::Func(func) => { + let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + func(&mut conn); + })); + } Command::Shutdown(func) => match conn.close() { Ok(()) => { func(Ok(()));