AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 19 Bitcoin

Merge bitcoin/bitcoin#36916: test: avoid BSD ephemeral-port collisions in HTTP clients

Public commit record

What the developer wrote

Authored by Hennadii Stepanov

100/100 · Strong
Merge bitcoin/bitcoin#36916: test: avoid BSD ephemeral-port collisions in HTTP clients

41c4df2eee61b0c564be6f39aa6e48dabe0a8870 test: avoid BSD ephemeral-port collisions in HTTP clients (will)

Pull request description:

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's `http.client` creates 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 with `BadStatusLine: POST / HTTP/1.1` because the client read back its own request.

This change adds a `netutil.HTTPConnection` subclass that sets the port range before connecting, and uses it in `AuthServiceProxy` and in the tests that open HTTP connections directly.

HTTPS is left unchanged because we don't serve RPC over TLS so it seems unnecessary.

ACKs for top commit:
hebasto:
re-ACK 41c4df2eee61b0c564be6f39aa6e48dabe0a8870.

Tree-SHA512: c39a61977e5b00907bda34040addf9cfce9c7502b08d7879e2fe504351d79d89b223ec487840a40296187b82e8dc2b0844d5060467b8c6c5b2e5886daae3ee8c
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a flaky-test problem on FreeBSD and OpenBSD, not a security vulnerability in the Bitcoin Core software users run. The test framework sometimes randomly picked a network source port that collided with a port used by the tests themselves. In rare cases a test HTTP client could accidentally connect to itself, causing confusing test failures. The fix makes Python's built-in HTTP client use the same port-range workaround already used for other test sockets. It only affects the automated test suite and only on BSD operating systems.

Recommended action

No production action needed. Test-only reliability improvement; ensure CI includes the new netutil unit test on FreeBSD/OpenBSD runners if available.

Security signals we found

01

Fixes self-connect scenario in test HTTP clients on BSD

02

Prevents source-port collision between test client and test listener ports

03

Only affects test framework, not production node networking

04

No change to consensus, P2P, wallet, or RPC server code

Risk score

Why this scored 19/100

Our methodology →
Potential impact 2/30
Exploitability 1/25
Stealth signal 1/15
Affected reach 2/15
Confidence 9/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.