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 <noreply@anthropic.com>
This commit is contained in:
@@ -301,9 +301,9 @@ private:
|
||||
std::string host_;
|
||||
std::string port_;
|
||||
std::string auth_; // Base64 encoded "user:password"
|
||||
bool connected_ = false;
|
||||
std::atomic<bool> connected_{false};
|
||||
std::atomic<bool> abort_{false}; // set cross-thread to abort an in-flight transfer
|
||||
bool warming_up_ = false;
|
||||
std::atomic<bool> warming_up_{false};
|
||||
std::string warmup_status_;
|
||||
std::string last_connect_error_;
|
||||
RpcFailureKind last_connect_kind_ = RpcFailureKind::None;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user