Skip to content

Commit a543a5e

Browse files
chopperbrianoclaude
andcommitted
RPC probe: fix spawn race and silence empty-body spam (win.28)
Two bugs surfaced by win.26's RPC liveness probe: - Race in ConsoleDashboard::render: _lastRpcProbe was only written at the end of probeRpcServer(), so every render in the window between spawn and completion (~1ms, but rendered every 500ms) spawned a new probe thread. Result: tens of TCP connects per second to the RPC port. Now set _lastRpcProbe before spawning, under the same mutex. - Dead early-return in Server::handleConnection: checked e.getMessage() == "empty", but DigiByteException's ctor wraps non-JSON messages in "Error during parsing of >>...<<", so the check never matched and every probe connection printed a DEBUG line. Now matches the wrapped form as well. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 402aa16 commit a543a5e

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ SET(PATCH_VERSION 0)
4040
SET(SO_VERSION 0)
4141

4242
# Windows port build number (increment for each Windows-specific release)
43-
SET(WIN_BUILD 27)
43+
SET(WIN_BUILD 28)
4444

4545
# Add source directory
4646
include_directories(src)

src/ConsoleDashboard.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,14 @@ void ConsoleDashboard::render() {
369369
// RPC::Server that becomes dangling if the detached accept-loop thread
370370
// dies, so trusting getRpcServerIfSet() can show a stale port for a
371371
// service that isn't actually listening.
372+
// Update _lastRpcProbe BEFORE spawning, otherwise every render in the
373+
// ~1ms window before the probe thread finishes will spawn a duplicate.
372374
{
375+
std::lock_guard<std::mutex> lock(_rpcProbeMutex);
373376
auto rnow = std::chrono::steady_clock::now();
374377
auto rElapsed = std::chrono::duration<double>(rnow - _lastRpcProbe).count();
375378
if (rElapsed >= 30.0 || !_rpcProbed) {
379+
_lastRpcProbe = rnow;
376380
std::thread([this]() { probeRpcServer(); }).detach();
377381
}
378382
}

src/RPC/Server.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,15 @@ namespace RPC {
208208
log->addMessage("RPC call #" + std::to_string(callNumber) + " method: " + method, Log::DEBUG);
209209
response = handleRpcRequest(request);
210210
} catch (const DigiByteException& e) {
211-
if (e.getMessage() == "empty") return; // stub accept — no real connection
212-
log->addMessage("Expected exception in RPC call #" + std::to_string(callNumber) + ": " + e.getMessage(), Log::DEBUG);
213-
response = createErrorResponse(e.getCode(), e.getMessage(), request);
211+
// Stub / probe connections: DigiByteException's ctor wraps the
212+
// raw message in "Error during parsing of >>...<<" because it
213+
// tries to JSON-parse the message, so match on the wrapped
214+
// form. Dashboard's RPC liveness probe (TCP connect + close)
215+
// produces this on every check.
216+
const std::string& em = e.getMessage();
217+
if (em == "empty" || em.find(">>empty<<") != std::string::npos) return;
218+
log->addMessage("Expected exception in RPC call #" + std::to_string(callNumber) + ": " + em, Log::DEBUG);
219+
response = createErrorResponse(e.getCode(), em, request);
214220
error = true;
215221
} catch (const std::exception& e) {
216222
log->addMessage("Unexpected exception in RPC call #" + std::to_string(callNumber) + ": " + e.what(), Log::DEBUG);

0 commit comments

Comments
 (0)