Repository navigation
dgb: NodeRPC calls have a deadline (BTC's DeadlineStream) - #2380
Merged
Merged
Conversation
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.
As DASH's NodeRPC (impl/dash/coin/rpc.cpp): - apply_socket_timeouts: after every connect (the async connect before check()'s first request, and sync_reconnect), the socket back in blocking mode with SO_RCVTIMEO / SO_SNDTIMEO of RPC_IO_TIMEOUT_SECONDS (12). beast's synchronous read and write ignore tcp_stream's expires_after, and asio's non_blocking flag (left set by async_connect) makes the kernel timeouts do nothing. A digibyted that keeps the socket open and sends nothing no longer holds Send() -- and m_io_mutex, so the other thread too -- forever. An inactivity bound per operation: a large template arriving steadily does not trip it. POSIX only. - close_stream after a request's last attempt failed: its reply may still come, and on the same connection the next request would read it (the id is the constant "curltest"; replies are not matched to requests). The next request reconnects. - set_io_timeout_sec for a shorter deadline (tests). Pinned: DgbNodeRpc.ASilentDaemonTimesOut (two attempts, each bounded, one reconnect between), ALateReplyIsNotTheNextRequests (a reply past the deadline is not the next request's).
The kernel SO_RCVTIMEO / SO_SNDTIMEO on a blocking socket does not bound asio's synchronous I/O: its recv takes the EAGAIN the kernel timeout gives for would_block and waits in poll(fd, -1), as long as the daemon does (DgbNodeRpc.ASilentDaemonTimesOut hung). As BTC's NodeRPC (rpc.cpp DeadlineStream): - apply_socket_timeouts puts the socket in user non-blocking mode, after every connect; - Send() reads and writes through DeadlineStream, which waits for readiness (poll) for at most the time left of ONE deadline for the call (RPC_IO_TIMEOUT_SECONDS, 30; set_io_timeout), its retry included, and fails with timed_out once it is spent; - past the deadline the request is not re-sent (the daemon has it), and the stream is closed, so its late reply is never read as the next request's; any other write or read failure retries once after a reconnect, as before. Pinned: DgbNodeRpc.ASilentDaemonTimesOut (returns at the deadline, one connection), ALateReplyIsNotTheNextRequests (the next request reconnects and reads its own reply).
frstrtr
added a commit
that referenced
this pull request
Nov 29, 2026
This was referenced Nov 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DGB NodeRPC calls to digibyted have a deadline, as BTC's NodeRPC does. Stacked on #2369.
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.