mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
test: avoid BSD ephemeral-port collisions in HTTP clients #36916
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!36916
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-bsd-http-ephemeral-ports"
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?
While stress-testing #36147 I noticed sporadic port collisions still occurring on FreeBSD.
set_ephemeral_port_range()keeps the source port out of the test port range, but only for sockets the framework creates itself. Python'shttp.clientcreates its sockets internally, so RPC and REST connections can still be given a source port inside the test range. A connection to a closed port can then connect to itself. For example, the wrong-RPC-port startup check failed withBadStatusLine: POST / HTTP/1.1because the client read back its own request.This change adds a
netutil.HTTPConnectionsubclass that sets the port range before connecting, and uses it inAuthServiceProxyand in the tests that open HTTP connections directly.HTTPS is left unchanged because we don't serve RPC over TLS so it seems unnecessary.
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.
LLM Linter (✨ experimental)
Possible places where named args for integral literals may be used (e.g.
func(x, /*named_arg=*/0)in C++, andfunc(x, named_arg=0)in Python):test/functional/test_framework/netutil.py:socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)2026-11-24 17:37:59
Concept ACK.
🔵 Suggestion · Mocked HTTP test leaves BSD source-port allocation unchecked
The mocked test verifies socket-option ordering but not actual source-port allocation; a supplemental BSD-only loopback check would cover whether the kernel applies the option during implicit binding.
Location:
test/functional/test_framework/netutil.py:300(head).Review coverage was incomplete.
Reviewed:
41c4df2eee61· Review report · Previous reportspermalink
Same happened here as well:
ACK
a2c3b1e27f, I have reviewed the code and it looks OK.Tested on FreeBSD in https://github.com/hebasto/bitcoin-core-nightly/pull/491, with the ephemeral port range narrowed so that the failure reproduces often.
Logs are available here: https://github.com/hebasto/bitcoin-core-nightly/actions/runs/45442316798.
The commit message says that the same can happen on OpenBSD. However, the OpenBSD kernel does not allow a socket to connect to itself.
Thanks for reviewing.
Do you have a source for this you can share? I'm struggling to find something myself...NVM I found it. Will amend the commit message.
Commit message amended.
re-ACK
41c4df2eee.cc @vasild @theStack