From d9143f0e186052fc22e519f1d2199524083b7915 Mon Sep 17 00:00:00 2001 From: DanS Date: Wed, 14 Oct 2026 07:21:07 -0500 Subject: [PATCH] fix(rpc): keep the worker alive on non-std throws; atomic flags The RPC worker loop only caught std::exception. A task that threw anything else - a non-std exception propagating out of a posted job - escaped the loop and tore down the worker thread, so every later RPC silently went unanswered. - The worker loop now also has a catch-all that swallows non-std throws and keeps the thread running. Such a job still loses its main-thread callback, exactly as the std::exception path already did; the only change is that the worker survives. - RPCClient's connected_ and warming_up_ flags are now atomic. They are read from the UI thread while the worker updates them, so the plain bools were a data race. Co-Authored-By: Claude Opus 4.8 --- src/rpc/rpc_client.h | 4 ++-- src/rpc/rpc_worker.cpp | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/rpc/rpc_client.h b/src/rpc/rpc_client.h index 9f2f4e5..bb3ba06 100644 --- a/src/rpc/rpc_client.h +++ b/src/rpc/rpc_client.h @@ -301,9 +301,9 @@ private: std::string host_; std::string port_; std::string auth_; // Base64 encoded "user:password" - bool connected_ = false; + std::atomic connected_{false}; std::atomic abort_{false}; // set cross-thread to abort an in-flight transfer - bool warming_up_ = false; + std::atomic warming_up_{false}; std::string warmup_status_; std::string last_connect_error_; RpcFailureKind last_connect_kind_ = RpcFailureKind::None; diff --git a/src/rpc/rpc_worker.cpp b/src/rpc/rpc_worker.cpp index 98b4da3..0ba9cf6 100644 --- a/src/rpc/rpc_worker.cpp +++ b/src/rpc/rpc_worker.cpp @@ -142,6 +142,10 @@ void RPCWorker::run() } } catch (const std::exception& e) { DEBUG_LOGF("[RPCWorker] Task threw: %s\n", e.what()); + } catch (...) { + // A raw post() job that throws still loses its MainCb (no worse than the + // std::exception path); this only keeps the worker thread alive. + DEBUG_LOGF("[RPCWorker] Task threw unknown exception\n"); } } }