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

bitcoin/bitcoin: PR #36724

1 minor finding · 3 suggestions

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

Findings

Link

[minor] · Forced chunking turns datagram requests into one-byte messages

On manual runs with port mapping enabled, the reproducer corrupts UDP and netlink request boundaries while successful sub-sends still satisfy the callers' length checks; functional tests disable this path.

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

Details and suggested fix

Sock::Send now splits every socket type, and requests shorter than 200 bytes take the one-byte path throughout. Each send() on the connected PCP/NAT-PMP UDP sockets creates a separate datagram, so retries repeat malformed requests and mapping fails with a network error. The Linux/FreeBSD netlink default-gateway query also uses SOCK_DGRAM. Its socket remains blocking, and its receive loop has neither a deadline nor an interrupt check. If the kernel accepts the fragments without replying, that receive blocks and StopMapPort() waits indefinitely in join(); this kernel-dependent outcome was not observed. In both callers, a successful aggregate return hides the broken message boundaries.

Port mapping defaults to enabled for an ordinary listening, non-proxy configuration, so manual runs can reach this code despite the test configuration. Restrict forced splitting to SOCK_STREAM, for example by checking SO_TYPE with GetSockOpt, and retain a single send() for datagram sockets. These failures would otherwise be reproducer artifacts, not stream-chunking failures.


Optional improvements

Link

[suggestion] · MSG_MORE lets Linux coalesce the forced P2P sub-sends

On Linux, preserving MSG_MORE on every sub-send explicitly encourages coalescing and weakens the reproducer's fragmentation stress, although the resulting receive boundaries were not measured.

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

Details and suggested fix

SocketSendData adds MSG_MORE for V1 headers with payloads, V1 payloads with a queued successor, and V2 READY packets with a queued successor. Forwarding that flag to every one-byte or 123-byte write asks Linux to hold data back even though P2P sockets already use TCP_NODELAY. Clear MSG_MORE on the forced sub-sends under #ifdef MSG_MORE, preserving MSG_NOSIGNAL and MSG_DONTWAIT. This removes an explicit obstacle to fragmentation without changing stream semantics. V2 handshake writes and HTTP writes do not set this flag, and platforms without it are unaffected. Scheduling and kernel coalescing can still combine writes, so this cannot guarantee separate packets or reads.


Link

[suggestion] · The new yield call lacks a direct <thread> include

sock.cpp relies on an indirect <thread> include in an IWYU-enforced directory, creating a likely unrelated CI failure; that failure is predicted from configuration, not observed.

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

Details and suggested fix

std::this_thread::yield() is declared by <thread>, but this file currently obtains it through util/threadinterrupt.h and sync.h. The IWYU job applies include fix-ups to src/util/*.cpp and fails if they leave a diff. Add #include <thread> directly so the reproducer does not introduce this unrelated tooling failure.


Link

[suggestion] · The slow-read drain retains tens of MiB of unnecessary response bodies

The slow-read HTTP test now retains over 46 MiB of response data and makes a full copy just to count replies, whereas the previous drain discarded receive chunks.

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

Details and suggested fix

recv_responses() retains every completed response in res, then copies the entire buffer with bytes(res). This caller asserts body size S > 7 MiB, waits for count > floor(32 MiB / S), and drains count + 2 replies. Thus the retained bodies exceed 32 MiB + 2S > 46 MiB before the copy; the exact peak was not measured. Add a count-only mode that retains framing state but discards completed responses and returns their status count. Keep full-data behavior for the other callers. This preserves complete-body checking and split-status-line handling without accumulating all the bodies in the test process.


Coverage details

Earlier concerns

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