Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f57cdee

Browse files
authoredJul 5, 2018
Prevent never-ending loop due to stratum mode autodetection (#1335)
Prevent never-ending loop on first connection
1 parent 7ebd167 commit f57cdee

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎libpoolprotocols/PoolClient.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace dev
2222
void setConnection(URI &conn)
2323
{
2424
m_conn = &conn;
25+
m_canconnect.store(false, std::memory_order_relaxed);
2526
}
2627

2728
virtual void connect() = 0;
@@ -49,6 +50,7 @@ namespace dev
4950
std::atomic<bool> m_subscribed = { false };
5051
std::atomic<bool> m_authorized = { false };
5152
std::atomic<bool> m_connected = { false };
53+
std::atomic<bool> m_canconnect = { false };
5254

5355
boost::asio::ip::basic_endpoint<boost::asio::ip::tcp> m_endpoint;
5456

‎libpoolprotocols/stratum/EthStratumClient.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ void EthStratumClient::disconnect_finalize() {
257257

258258
// If we got disconnected during autodetection phase
259259
// reissue a connect lowering stratum mode checks
260-
if (!m_conn->StratumModeConfirmed())
260+
// m_canconnect flag is used to prevent never-ending loop when
261+
// remote endpoint rejects connections attempts persistently since the first
262+
if (!m_conn->StratumModeConfirmed() && m_canconnect.load(std::memory_order_relaxed))
261263
{
262264
unsigned l = m_conn->StratumMode();
263265
if (l > 0)
@@ -440,6 +442,7 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec)
440442

441443
// Immediately set connecting flag to prevent
442444
// occurrence of subsequents timeouts (if any)
445+
m_canconnect.store(true, std::memory_order_relaxed);
443446
m_connecting.store(false, std::memory_order_relaxed);
444447
m_conntimer.cancel();
445448

0 commit comments

Comments
 (0)
This repository has been archived.