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

pull willcl-ark wants to merge 1 commits into bitcoin:master from willcl-ark:fix-bsd-http-ephemeral-ports changing 8 files +67 −12
  1. willcl-ark commented at 3:43 PM on November 19, 2026: member

    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.

  2. test: avoid BSD ephemeral-port collisions in HTTP clients
    FreeBSD and OpenBSD allocate ephemeral ports from ranges that overlap
    the functional framework's fixed test ports. An outgoing localhost
    connection can therefore select its destination port as its source port
    and connect to itself. The wrong-RPC-port startup test exposed this on
    FreeBSD as BadStatusLine: POST / HTTP/1.1, consistent with reading its
    own request instead of receiving the expected connection refusal.
    
    The existing set_ephemeral_port_range() protection only covers
    explicitly created sockets.
    
    Python's HTTP clients create their sockets internally, so apply the
    helper through their connection factory before connecting. Share the
    protected HTTPConnection across the RPC proxy and direct HTTP callers,
    without changing system-wide settings. The HTTPS path is left alone
    because bitcoind does not serve RPC over TLS.
    
    Also adds a framework unit test checking that the option is set before
    connect() for IPv4 and IPv6 on both platforms.
    a2c3b1e27f
  3. DrahtBot added the label Tests on Nov 19, 2026
  4. DrahtBot commented at 3:43 PM on November 19, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK hebasto

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. hebasto commented at 3:45 PM on November 19, 2026: member

    Concept ACK.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-19 19:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me