fix(rpc): abort in-flight curl on disconnect/shutdown to avoid UI freezes
stop()-ing a worker that is mid curl_easy_perform joined on the UI thread, so a slow/hung transfer froze the UI until the request timeout. Add RPCClient:: requestAbort() (a thread-safe atomic read by a curl progress callback that aborts the transfer), and call it before stopping the workers on disconnect (onDisconnected) and shutdown (beginShutdown + the synchronous fallback). The flag is cleared on each connect() so a fresh connection never starts aborted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@@ -87,6 +88,18 @@ public:
|
||||
*/
|
||||
bool isConnected() const { return connected_; }
|
||||
|
||||
/**
|
||||
* @brief Ask an in-flight call() to abort as soon as possible (thread-safe).
|
||||
*
|
||||
* Set from another thread (e.g. before stop()-ing the worker on disconnect/shutdown):
|
||||
* a curl progress callback aborts the transfer, so a blocked curl_easy_perform returns
|
||||
* promptly instead of freezing the UI thread's join() until the request timeout. Cleared
|
||||
* on the next connect(); abortRequested() is read by the progress callback.
|
||||
*/
|
||||
void requestAbort();
|
||||
void clearAbort();
|
||||
bool abortRequested() const noexcept { return abort_.load(std::memory_order_relaxed); }
|
||||
|
||||
/**
|
||||
* @brief True if the last connect() succeeded but daemon returned a warmup error.
|
||||
* The curl handle is valid and auth succeeded — RPC calls will throw warmup errors
|
||||
@@ -236,6 +249,7 @@ private:
|
||||
std::string port_;
|
||||
std::string auth_; // Base64 encoded "user:password"
|
||||
bool connected_ = false;
|
||||
std::atomic<bool> abort_{false}; // set cross-thread to abort an in-flight transfer
|
||||
bool warming_up_ = false;
|
||||
std::string warmup_status_;
|
||||
std::string last_connect_error_;
|
||||
|
||||
Reference in New Issue
Block a user