Skip to content

dgb: NodeRPC serves one request at a time on its one stream - #2369

Merged
frstrtr merged 4 commits into
masterfrom
dgb/rpc-send-mutex
Nov 29, 2026
Merged

frstrtr merged 4 commits into
masterfrom
dgb/rpc-send-mutex

Conversation

@frstrtr

@frstrtr frstrtr commented Nov 28, 2026

Copy link
Copy Markdown
Owner

dgb::coin::NodeRPC serves one request at a time on its single digibyted HTTP stream.

  • Two threads share the stream: the stratum IO thread (getblocktemplate, stratum submitblock, block-verify getblockheader) and the sharechain compute thread under the tracker lock (won-block submit_block_hex, then record_found_block's getblockheader). Unordered, two requests could interleave writes/reads and take each other's replies; on a won block both submitblocks go out within moments of each other.
  • A recursive mutex m_io_mutex covers every use of the stream, the request and the connected flag: Send (write + read of one request, and its reconnect), connect and its resolve/connect handlers, reconnect, sync_reconnect. Recursive because the connect check and a failed request's reconnect send from inside it. A cancelled connect returns before taking the lock.
  • No change to request content or timeouts (read/write timeouts are a separate follow-up).

Tests

  • DgbNodeRpc.TwoThreadsGetTheirOwnRepliesOnOneConnection (in dgb_coin_node_seam_test): two threads × 200 requests on one keep-alive connection to a local JSON-RPC server; every reply is the sender's own. TIMEOUT 60; the fake server closes its acceptor after its one accept, so a reconnect fails fast.
  • Without the Send lock: 2 of 3 runs fail (bad=163, bad=142), 1 hangs; with it: pass.
  • TSan (-fsanitize=thread, run under setarch -R): pass, 0 reports.
  • All 89 DGB targets: 873/873; core_test pass; tools/ci/check_test_target_allowlist.py OK.

The digibyted RPC connection is one beast HTTP stream, used from the
stratum IO thread (getblocktemplate, submitblock) and from the HTTP thread
(getblockheader for the dashboard), with nothing ordering them: two
requests at once could interleave their writes and reads on the socket
and take each other's replies. A recursive mutex (m_io_mutex) now covers
every use of the stream, the request and the connected flag: Send (the
write and the read of one request, and its reconnect), connect and its
resolve/connect handlers, reconnect and sync_reconnect. Recursive, because
the connect check and a failed request's reconnect send from inside it.

Pinned: DgbNodeRpc.TwoThreadsGetTheirOwnRepliesOnOneConnection (rides
dgb_coin_node_seam_test): two threads, 200 requests each, on one
keep-alive connection to a local JSON-RPC server; every reply is the
sender's own. Clean under TSan.
The KAT's server looped back to a blocking accept after the client's
connection closed, and closing the acceptor from the test thread does not
interrupt it on Linux, so the join hung. It serves one connection and
returns when the client closes it. Test only.
…lock; the KAT fails fast

- The second thread on the NodeRPC stream is the sharechain compute
  thread, under the tracker lock, when a share is a block
  (won_block_dispatch submit_block_hex, then record_found_block's
  getblockheader). It runs against the IO thread (the stratum
  submitblock, the GBT tip, the block-verify getblockheader). The comment
  in rpc.hpp and the KAT header say so; 5531693 named an HTTP thread.
- The async_connect handler returns on operation_canceled before it
  takes m_io_mutex.
- KAT DgbNodeRpc.TwoThreadsGetTheirOwnRepliesOnOneConnection: the fake
  server caches its port and closes the acceptor right after its one
  accept, so a reconnect is refused at once; the test has a 60 s ctest
  TIMEOUT. The worker flag that selects getmininginfo is named
  mininginfo.
frstrtr added a commit that referenced this pull request Nov 29, 2026
#2369 refreshed onto master (the Windows smoke step, #2367, among it).
@frstrtr
frstrtr merged commit 76714dc into master Nov 29, 2026
54 checks passed
frstrtr added a commit that referenced this pull request Nov 29, 2026
#2369 is on master (76714dc); its files are this branch's, with the
NodeRPC deadline on top.
frstrtr added a commit that referenced this pull request Nov 29, 2026
DGB NodeRPC calls to digibyted have a deadline, as BTC's NodeRPC does. Stacked on #2369.

- Every request (write and read) runs on a stream that bounds each read_some/write_some by one absolute deadline per call: the socket is in user non-blocking mode and the wait for readiness is poll() with the time left, failing with timed_out once it is spent. A kernel SO_RCVTIMEO does not bound asio's synchronous recv (asio waits in poll(fd, -1) on EAGAIN), so it is not used.
- A request that times out closes the stream; the next call reconnects. A request past its deadline is not re-sent.
- Send(), close_stream() and the socket setup take #2369's I/O mutex.

Tests: a peer that accepts and never answers (the call returns timed_out within the deadline, the stream is closed, the next call reconnects); a peer that answers slowly within the deadline (the call succeeds); concurrent calls with the I/O mutex. All DGB targets 875/875; oracle harness both directions PASS.
frstrtr added a commit that referenced this pull request Nov 29, 2026
master holds #2369, #2372, #2380 and #2376. main_dgb_wiring_test.cpp keeps
both sides' new tests (the header-chain rules and the single stratum
listener; the mint's block body and the GBT poller).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant