1 minor finding · 4 suggestions
Findings
[minor] · Forced chunking corrupts UDP and netlink requests
This test reproducer also fragments message-oriented requests, breaking real port-mapping and gateway queries outside the intended TCP stress scope; the normal test harness disables NAT-PMP.
Location: src/util/sock.cpp:62 (head).
Details and suggested fix
PCPSendRecv uses connected UDP sockets, and QueryDefaultGatewayImpl uses an AF_NETLINK datagram socket on Linux and FreeBSD. Their requests are under 200 bytes, so this loop sends each byte as a separate message rather than preserving the request boundary. If all sub-sends succeed, the aggregate return still passes the callers' length checks. Retrying only resends malformed fragments. Restrict forced chunking to SOCK_STREAM and keep one send() for message-oriented sockets.
Outside the harness, NAT-PMP defaults to enabled unless option interactions such as -proxy or -listen=0 disable it. Functional and unit tests disable NAT-PMP, and PCP unit tests mock Send, so those tests do not expose this artifact. The netlink socket is blocking and its receive loop has no timeout or interrupt check. If the kernel accepts and silently drops all fragments, the mapport thread can remain in Recv, making StopMapPort() wait indefinitely in join(). That shutdown consequence is kernel-dependent and unobserved.
Optional improvements
[suggestion] · MSG_MORE counteracts P2P small-chunk stress
The reproducer preserves Linux's MSG_MORE corking hint on every P2P sub-send, encouraging coalescing that works against the small-write stress; actual packetization was not measured.
Location: src/util/sock.cpp:64 (head).
Details and suggested fix
SocketSendData sets MSG_MORE when the transport reports more data. For V1 this includes headers with a payload and payloads followed by another queued message. Passing that flag unchanged to every sub-send encourages Linux to retain partial frames instead of pushing the deliberately small writes. Clear MSG_MORE in the reproducer's sub-sends when the flag is available. It is a batching hint, so removing it preserves stream correctness, although kernel coalescing can still prevent a one-to-one relationship between writes and receiver reads.
[suggestion] · Framework writes bypass the new chunking stress
Ordinary Python HTTP and P2P writes bypass the reproducer, so they gain no deliberate small-chunk input coverage at the node; branch-built senders and existing explicit split tests provide some inbound coverage.
Location: src/util/sock.cpp:55 (head).
Details and suggested fix
BitcoinHTTPConnection.send_raw uses Python's sendall, and P2PConnection.send_raw_message uses asyncio's transport.write. Neither passes through Sock::Send, while node-side Sock::Recv remains a plain recv(). To stress node parsing independently of which client sends the bytes, add an optional fixed read-size cap for stream sockets in this reproducer. Apply the same cap to MSG_PEEK and ordinary reads so RecvUntilTerminator can still consume exactly the amount established by its peek. Whether this extension would reveal additional failures is unknown.
[suggestion] · The slow-read test still accepts a truncated final response
The new helper tracks complete responses, but the slow-read test still accepts clean EOF midway through the final body because it only counts status lines; this assertion weakness predates the PR.
Location: test/functional/interface_http.py:118 (head).
Details and suggested fix
If the first count + 1 responses are complete and the server closes after the next response's status line and headers but before its Content-Length body ends, recv_responses(count + 2) returns the partial bytes with received < count + 2. The caller nevertheless finds enough HTTP/1.1 200 markers and passes, with no later completeness assertion on that connection. Assert that received == count before returning on EOF. A connection closing after a complete response would still pass.
[suggestion] · The slow-read drain retains and copies every response body
The functional test now accumulates all drained responses and copies them at return, retaining over 46 MiB of body data on a complete drain merely to count status lines; peak memory was not measured.
Location: test/functional/interface_http.py:920 (head).
Details and suggested fix
recv_responses advances pos without removing consumed bytes from its bytearray, then creates a full copy with bytes(res). Each body in this fixture exceeds 7 MiB. The stall condition requires count > MAX_BODY_SIZE // response_body_size, so draining count + 2 complete responses retains more than 32 MiB plus two bodies. The old loop discarded each bounded read. Add a streaming count-only drain mode that discards consumed body bytes while preserving framing state across reads and returns the number of complete responses, leaving content-returning behavior available to callers that inspect bodies.