mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:26:38 +00:00
http: Preserve socket errors before unlocking #37005
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!37005
Loading…
Reference in a new issue
No description provided.
Delete branch "http-preserve-socket-errors"
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?
Fixes #36973.
Background
For Windows MinGW build with
DEBUG_LOCKORDER, releasingm_sock_mutexcallsstd::this_thread::get_id(). This can clear the Windows last-error value to 0 before the HTTP code reads it.httpserver_tests/http_socket_error_teststest case mockSend()fails on the first call, then succeed on the next call. By clearing the errorWSAEWOULDBLOCK, the test server does not retry and instead disconnects, causing the test failure.Changes
WSAGetLastError()call into the critical sections for socket pathsSend()andRecv()Recv()inhttpserver_tests/http_socket_error_testsRelated work
identified in #36973.
32.xwas requested in the discussion on #36973. This patchtargets
master; the backport would be separate.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.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments.
🔵 Suggestion · CI omits the configuration needed by the socket regression tests
The new socket tests would likely pass without the fix in in-tree CI because its MinGW build omits
DEBUG_LOCKORDER; this conclusion comes from configuration inspection, not an observed CI run.Location:
src/test/net_tests.cpp:1846(head).🔵 Suggestion · PR title and description omit the P2P fix and test
The PR describes only HTTP, although it also changes P2P send and receive error handling and adds
net_tests/socket_error_tests, obscuring the scope reviewers and backporters need to assess.Location:
src/net.cpp:1668(head).Reviewed:
0409d2eadc60· Review report · Previous reportspermalink
approach ACK
the error code from a failed
recv()/send()is thread-local, so anything that runs on the same thread before the http server code comes around to read it can overwrite it. in this case, releasing the lock,m_sock_mutex, does exactly that in debug builds. a harmless"try again"error (WSAEWOULDBLOCK(10035)) then gets read as0, whichIOErrorIsPermanenttreats as permanent and fatal thus dropping the clientso, reading it immediately after either socket API call, while still holding the lock, avoids that. MSDN docs also explicitly recommends doing it this way
also, +1 to Ralph's suggestion. the existing test only simulates failures on
Send(), so we would not catch a regression on theReceive()side if the code is changed in an erroneous way, later onThank you for the review @winterrdog.
I have addressed Ralph's suggestion and added a
Recv()unit test inhttp_socket_error_tests.Concept ACK but some housekeeping about this PR:
{WITH_LOCK...)};not{ WITH_LOCK...) };In general the PR description reads very LLM-y. Read through the https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md then my suggestion would be, completely re-write the PR description without AI assistance. If you can't, it probably means someone else should take over this PR. It's a pretty simple change and closes a pretty simple issue so I'd rather you learn how to be a valuable contributor.
re: https://github.com/bitcoin/bitcoin/pull/37005#issuecomment-7284954117
this reminded me of this comment: https://github.com/bitcoin/bitcoin/pull/36305#pullrequestreview-5667835205. sometimes it is the reverse, like in that case. so i had assumed it was OK here. the developer notes support your idea, though
nit: "once" is a bit ambiguous next to the
Send()paragraph. maybe something like:what do you think ?
@pinheadmz Thank you for the feedback and review. I have updated the PR description accordingly and made the minor whitespace nit fix.
@winterrdog The test comment has been updated. I also agree that this is a test-driven change as the open issue #36973 served as the initial premise for the PR. The developer notes were helpful so that I know for next time.
Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits
Locally confirmed this fix does solve the error described in https://github.com/bitcoin/bitcoin/issues/36973
from: https://github.com/bitcoin/bitcoin/pull/37005#issuecomment-7284954117:
shouldn't this be addressed here, as well ?
i think let us do it all here, and backport at once. what do others suggest ?
if other reviewers agree, the PR author can start off with a patch like this:
net.cpppatchi think
net_tests.cppis a good home to add the new testsThanks for the feedback.
@winterrdog Applied the same fix to P2P connections and added the same
Send()andRecv()test cases.@maflcko Squashed.
🚧 At least one of the CI tasks failed.
Task
32 bit ARM: https://github.com/bitcoin/bitcoin/actions/runs/47067651345/job/144136562068LLM reason (✨ experimental): build_fail: Compilation of
net_tests.cppfails because-Werror=overloaded-virtualtreats a hidden virtual assignment operator warning as an error.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening.
A functional or integration test failure may be intermittent or unrelated to this pull request.
If no dedicated issue thread exists, create a new one to track it.
Leave a comment here, if you need help tracking down a confusing failure.
the PR title needs an update that includes
nettoo, e.g.net, http: Preserve socket errors before unlocking. same goes for the PR description, since the P2P server now gets the same fix as the HTTP serverside note: when i run
.\build\bin\test_bitcoin.exe --run_test=net_testslocally, it results in:i doubt it has sth to do with this PR because the assertion failure happens on
mastertoo. anyone with an idea as to why it happens ?could you add a short doc comment atop
ErrorSock, like the one inhttpserver_tests.cpp?it would help future readers see why the first
Send()/Recv()failsnit:
> 0only proves the counter moved, not that the bytes actually reached the socket. IMO, checking the pipe against the counter is stronger: