From ac11b81c62f6153df62d492782e52b41440bc92e Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 25 Oct 2025 12:13:14 +0700 Subject: [PATCH] Fixed mishandled timeouts. --- src/proxy/Miner.cpp | 8 ++++---- src/proxy/Miner.h | 12 +++++------- src/proxy/Miners.cpp | 15 +++++++-------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/proxy/Miner.cpp b/src/proxy/Miner.cpp index 4e1cc35..6f83ecc 100644 --- a/src/proxy/Miner.cpp +++ b/src/proxy/Miner.cpp @@ -58,7 +58,7 @@ namespace xmrig { static int64_t nextId = 0; char Miner::m_sendBuf[16384] = { 0 }; Storage Miner::m_storage; -} +} // namespace xmrig xmrig::Miner::Miner(const TlsContext *ctx, uint16_t port, bool strictTls) : @@ -67,7 +67,7 @@ xmrig::Miner::Miner(const TlsContext *ctx, uint16_t port, bool strictTls) : m_tlsCtx(ctx), m_id(++nextId), m_localPort(port), - m_expire(Chrono::currentMSecsSinceEpoch() + kLoginTimeout), + m_expire(Chrono::steadyMSecs() + kLoginTimeout), m_timestamp(Chrono::currentMSecsSinceEpoch()) { m_reader.setListener(this); @@ -215,7 +215,7 @@ bool xmrig::Miner::parseRequest(int64_t id, const char *method, const rapidjson: algorithms.reserve(value.Size()); for (const auto &i : value.GetArray()) { - Algorithm algo(i.GetString()); + const Algorithm algo(i.GetString()); if (!algo.isValid()) { continue; } @@ -324,7 +324,7 @@ bool xmrig::Miner::send(BIO *bio) void xmrig::Miner::heartbeat() { - m_expire = Chrono::currentMSecsSinceEpoch() + kSocketTimeout; + m_expire = Chrono::steadyMSecs() + kSocketTimeout; } diff --git a/src/proxy/Miner.h b/src/proxy/Miner.h index 7ce4f45..ba1577e 100644 --- a/src/proxy/Miner.h +++ b/src/proxy/Miner.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2021 SChernykh - * Copyright 2016-2021 XMRig , + * Copyright 2018-2025 SChernykh + * Copyright 2016-2025 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,12 +25,10 @@ #ifndef XMRIG_MINER_H #define XMRIG_MINER_H - #include #include #include - #include "3rdparty/rapidjson/fwd.h" #include "base/kernel/interfaces/ILineListener.h" #include "base/net/tools/LineReader.h" @@ -147,7 +145,7 @@ private: String m_rigId; String m_user; String m_signatureData; - uint8_t m_viewTag; + uint8_t m_viewTag = 0; Tls *m_tls = nullptr; uint16_t m_localPort; uint64_t m_customDiff = 0; @@ -166,6 +164,6 @@ private: }; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_MINER_H */ +#endif // XMRIG_MINER_H diff --git a/src/proxy/Miners.cpp b/src/proxy/Miners.cpp index b8817b8..1b9837d 100644 --- a/src/proxy/Miners.cpp +++ b/src/proxy/Miners.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2025 SChernykh + * Copyright 2016-2025 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,8 +25,7 @@ #include - -#include "base/io/log/Log.h" +#include "base/tools/Chrono.h" #include "base/tools/Handle.h" #include "proxy/events/CloseEvent.h" #include "proxy/events/ConnectionEvent.h" @@ -34,9 +33,9 @@ #include "proxy/Miners.h" -xmrig::Miners::Miners() +xmrig::Miners::Miners() : + m_timer(new uv_timer_t) { - m_timer = new uv_timer_t; m_timer->data = this; uv_timer_init(uv_default_loop(), m_timer); uv_timer_start(m_timer, [](uv_timer_t *handle) { static_cast(handle->data)->tick(); }, kTickInterval, kTickInterval); @@ -101,7 +100,7 @@ void xmrig::Miners::remove(Miner *miner) void xmrig::Miners::tick() { - const uint64_t now = uv_now(uv_default_loop()); + const uint64_t now = Chrono::steadyMSecs(); std::vector expired; for (auto const &kv : m_miners) { @@ -114,7 +113,7 @@ void xmrig::Miners::tick() return; } - for (auto miner : expired) { + for (auto *miner : expired) { miner->close(); } }