WIP: [DONTMERGE] Test run with reproducer for forced chunked send

bitcoin/bitcoin: PR #36724

1 minor finding · 5 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · Forced chunking changes datagram message boundaries

With port mapping enabled, this DONTMERGE build sends malformed UDP and netlink requests; a possible netlink shutdown hang additionally depends on unverified kernel behavior.

Location: src/util/sock.cpp:61 (head).

Details and suggested fix

Sock::Send also serves SOCK_DGRAM sockets. Requests shorter than 200 bytes now become separate one-byte messages, rather than pieces of one stream. The summed return value can still pass the callers' length checks. This corrupts PCP/NAT-PMP requests, so their bounded retry loop cannot establish a mapping. On Linux and FreeBSD it also splits the netlink gateway request. If those sends succeed and the kernel discards the undersized messages without replying, the mapport thread blocks in the netlink receive loop, which has no timeout or interrupt check. Shutdown then waits in StopMapPort()'s join. That kernel-dependent hang was not verified.

This affects manual runs with port mapping enabled, which is the default. The functional and unit configurations disable it, and PCP unit tests override Send, so they do not validate this datagram behavior. Restrict the hook to SOCK_STREAM, using SO_TYPE through GetSockOpt, and retain a single send() for other socket types.


Optional improvements

Link

[suggestion] · The v2 setban exclusion lacks a failure explanation

The exclusion lacks a failure log or cause, leaving the source-inferred early-close explanation unconfirmed and preventing readers from distinguishing reproducer effects from a robustness bug.

Location: test/functional/test_runner.py:251 (base).

Details and suggested fix

Commit 9990c84b records only a temporary ignore for this run. A possible cause is that node1 drops the banned connection at accept while the per-byte send loop is still running. A later send error can make the loop return fewer than 24 bytes, leaving m_sent_v1_header_worth false and preventing the v1 retry that rpc_setban.py --v2transport expects. Record the failing assertion and relevant node log in the commit message or PR, together with the confirmed cause if available. No failure output was supplied here, and base nonblocking send() also permits short returns, so this explanation alone does not establish a reproducer-only artifact.


Link

[suggestion] · Forwarded MSG_MORE works against forced fragmentation

On Linux, retaining MSG_MORE encourages coalescing of the forced v1 header chunks, reducing opportunities to exercise split-header parsing; the actual packetization in this run was not measured.

Location: src/util/sock.cpp:64 (head).

Details and suggested fix

SocketSendData sets MSG_MORE for every payload-bearing v1 header and for payloads followed by another queued message. This loop forwards it to every small send. On Linux, MSG_MORE provides per-call TCP corking, so the one-byte header sends can be combined before transmission despite TCP_NODELAY. V2 handshake sends do not take this path because their more flag is false before READY. Clear MSG_MORE inside this test-only loop, guarded by #ifdef MSG_MORE, to remove the deliberate corking. TCP may still coalesce chunks, so this improves the stress opportunity rather than guaranteeing small receive callbacks.


Link

[suggestion] · Python-to-node traffic bypasses the chunking hook

The hook leaves general Python-to-node writes unfragmented, limiting receive-side stress in Python-driven tests even though node-to-node traffic and selected explicit split-input cases still exercise node readers.

Location: src/util/sock.cpp:72 (head).

Details and suggested fix

P2PConnection.send_raw_message passes a whole buffer to transport.write, and BitcoinHTTPConnection.send_raw uses sendall; neither reaches Sock::Send. With Sock::Recv unchanged, this run does not systematically introduce small reads into bitcoind's v1, v2 handshake, or HTTP parsers when Python drives the connection. Node-to-node and bitcoin-cli traffic do reach the hook, and existing tests explicitly split selected inputs, so this is a directional coverage limitation rather than an absence of node-side coverage. Extend the stress mode to the Python send helpers, scheduling small writes with opportunities for the receiver to run between them. As with the C++ hook, that increases fragmentation opportunities without guaranteeing receive boundaries.


Link

[suggestion] · Split-handshake fixes lack deterministic regression coverage

The Python responder fixes depend on uncommon random inputs and read boundaries that no checked-in test forces, so regressions can escape CI after the reproducer is removed.

Location: test/functional/test_framework/v2_p2p.py:142 (head).

Details and suggested fix

Add deterministic tests for the invariants fixed by b45fa006 and 45bae4f1. Feed respond_v2_handshake one matching magic byte, then a buffer beginning with a mismatch. Assert per-call consumption and that trimming by those counts lets complete_handshake reconstruct the intended 64-byte key. Separately, force responder garbage to be empty and drive two partial-key callbacks through P2PConnection; assert that it generates and sends only one key. These distinguish the old implementations without relying on random keys, the 1-in-4096 empty-garbage draw, or socket timing. The existing split-prefix test exercises the C++ responder instead. Register the new framework unit tests in TEST_FRAMEWORK_MODULES.


Link

[suggestion] · The slow-read drain retains every large response body

check_slow_read_throttle now retains and copies tens of MiB of response bodies merely to count responses, increasing functional-test memory pressure; no resource failure or peak-memory measurement was observed.

Location: test/functional/interface_http.py:117 (head).

Details and suggested fix

Each REST body exceeds 7 MiB, and the stall condition requires count > MAX_BODY_SIZE // response_body_size. Draining count + 2 complete responses therefore accumulates tens of MiB in recv_responses' bytearray before allocating a full bytes copy. The base loop retained only receive buffers of up to 10 MiB. Add a framed drain mode that counts complete responses while incrementally discarding their bodies, then return the count to this caller. Keep the Content-Length framing so a status marker split across reads remains handled correctly.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.