perf(miner): abort xmrig stat fetches on stop

The miner's stats and pool-API fetches are blocking HTTP calls on the
monitor thread with multi-second timeouts. When the miner was stopped,
stop() still had to wait out an in-flight request before the monitor
thread could join.

- Both fetches now install a curl progress callback that aborts the
  transfer as soon as a stop is requested, so a request in flight ends
  promptly instead of running down its timeout.
- An abort triggered by stop is treated as a clean cancellation, not a
  fetch failure, so it is not logged or counted against the failure
  warning.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 06:26:13 -05:00
co-authored by Claude Opus 4.8
parent 60b3ad5d5a
commit b407b8927a
2 changed files with 10 additions and 0 deletions
+7
View File
@@ -745,12 +745,16 @@ void XmrigManager::fetchStatsHttp() {
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 2000L); // 2s timeout — generous for loaded system
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 1000L); // 1s connect timeout
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L); // Avoid signal issues in threads
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, &XmrigManager::abortCb);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, this);
CURLcode res = curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
if (res != CURLE_OK) {
if (should_stop_.load()) return; // aborted by stop(): not a failure
static int s_fail_count = 0;
if (++s_fail_count <= 5 || s_fail_count % 30 == 0) {
DEBUG_LOGF("[WARN] XmrigManager::pollStats: curl failed (%d): %s url=%s\n",
@@ -845,6 +849,9 @@ void XmrigManager::fetchPoolApiStats() {
// pool.dragonx.cc sits behind Cloudflare and 403s odd User-Agents.
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; ObsidianDragon)");
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, &XmrigManager::abortCb);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, this);
CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl);