mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
cli: respect -rpcclienttimeout even when sending #36676
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36676
Loading…
Reference in a new issue
No description provided.
Delete branch "2610_cli_socket_error_fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The move away from libevent introduced a small regression in this regard. In #36299, we switched the timeout to apply per socket wait, but continued on to another socket wait in case of timeout, instead of returning. See commit message for details.
In general, we also shouldn't ignore
Sock::Wait's errors and timeouts by silently retrying forever.Fix these issues by returning instead when
Sock::Waittimes out or returns an error.Tentative bot functional test for this in second commit that appears to be robust enough.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Well, scratch that. It's flaky on Windows. I'm dropping it from this PR: reviewers can easily bot-implement one locally to sanity check the behaviour. The only robust alternative would be a unit test, but would require some refactoring. That's overkill for this PR's trivial fix to the CLI.
2 previous suggestions
Previous suggestions (2)
[Suggestion · still present] Send timeouts are reported as generic send failures
When
-rpcclienttimeoutexpires during sending, the CLI does not identify the timeout, unlike when the same timeout occurs during receiving.When
Sock::Wait()times out, it returns withoccurredset to 0.SendRequest()then returns false, andPost()reportsFailed to send HTTP requestfor every false return. The resulting CLI message does not point to-rpcclienttimeoutas the cause or suggest raising it. By contrast, a receive timeout is reported as(timeout). ThrowCConnectionFailed{"timeout"}or a send-specific timeout message when the wait returns with no events. Keep the generic failure for error events and permanent send errors. Both paths still raiseCConnectionFailed, so-rpcwaitretry behavior is unchanged.Location:
src/bitcoin-cli.cpp:917(head).First reported at
e5d9a7e04b50c723aeb65984e5048ffd098f6737. Original review. Last checked ate5d9a7e04b50c723aeb65984e5048ffd098f6737.[Suggestion · still present] No test covers the stalled-send timeout path
Restoring the old
continuewould leave the tests unable to catch a return of the indefinite hang.The raw-socket test sends a response and then calls
recv(), so the client's small request does not block and the test does not reach the branch where the wait ends withoutSendEvent. Add a test that creates backpressure: for example, have a listener set a smallSO_RCVBUFbefore listening, accept the connection, and never read from it. Runbitcoin-cli -rpcclienttimeout=1with a request large enough to fill the loopback buffers, such as a multi-megabyte argument passed through-stdintoecho, and assert that the command fails rather than hanging until the harness timeout. A small request fits in the kernel send buffer and only exercises the receive timeout. Since backpressure was unreliable on Windows in an earlier attempt, the test may need to be skipped on platforms where it cannot be produced reliably.Location:
src/bitcoin-cli.cpp:917(head).First reported at
e5d9a7e04b50c723aeb65984e5048ffd098f6737. Original review. Last checked ate5d9a7e04b50c723aeb65984e5048ffd098f6737. The author plans to address this separately. Author reply 2026-10-27T17:18:03ZReview coverage was incomplete.
Review limitations
Base:
b1172114df07· Head:e5d9a7e04b50· Full review reportACK
e5d9a7e04btested ACK
e5d9a7e04bI also had it in my backlog (came up a few weeks ago when I was reviewing a different change - cc: @maflcko).
Tested locally that a stalled upload reports a send failure and that the provided fix is correct.
ACK
e5d9a7e04bBuilt and tested on macos/arm64.
The undesired behavior is not just an ordinary timeout while waiting for a server reply, but a timeout while waiting for the socket to be writable on the client end. Even if no server exists at all, the client's kernel's TCP stack may still happily receive bytes with no where to send them.
To reproduce I ran a trivial accept-and-do-not-read server and made bitcoin-cli connections to it. The only way to garuntee the "wait forever" behavior is to send an excessive amount of data with bitcoin-cli and trigger TCP backpressure so the socket actually becomes not writable.
On master, in that case, we
continueto wait forever. With this patch, we quit with(Failed to send HTTP request).One thing thats not exactly clear in the PR description or commit message is that a timeout is NOT treated as an error.
select()andpoll()return0on timeout, and soWait()andWaitMany()still returntrue. On master, we already quit on error. This PR also quits on timeout.Show Signature
pinheadmz's public key is on openpgp.org