Review report

bitcoin/bitcoin: PR #36724

2 minor findings · 2 suggestions

Findings

Link

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

PCP/NAT-PMP and netlink requests use this wrapper too, so successful sub-sends can report the expected byte count while replacing a valid request with separate one-byte datagrams.

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

Details and suggested fix

The loop applies to every socket type, and requests shorter than 200 bytes take the one-byte path throughout. PCPSendRecv uses connected UDP sockets for its 2-, 12-, and 60-byte requests; QueryDefaultGatewayImpl uses a netlink datagram socket. Both only check the aggregate byte count, which cannot detect the changed message boundaries. PCP/NAT-PMP mapping fails after errors or bounded retries rather than exercising stream reassembly. The netlink socket remains blocking, and its receive loop has no deadline or interruption check. If the kernel silently discards these undersized messages without replying, that receive blocks indefinitely and StopMapPort() waits in join(); the checkout does not establish whether the kernel does so. This is reachable with port mapping enabled, including normal listening defaults without a proxy, although common test setup disables mapping and PCP tests override Send. Restrict forced chunking to SOCK_STREAM, for example using SO_TYPE, and preserve a single send() for datagram sockets so this experiment does not introduce unrelated protocol failures.


Link

[minor] · MSG_MORE works against the forced small sends on Linux

Passing MSG_MORE to every sub-send lets Linux coalesce the one-byte V1 header writes, weakening this reproducer's receive-fragmentation stress.

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

Details and suggested fix

V1Transport::GetBytesToSend reports more=true for every header followed by a payload, and SocketSendData translates that into MSG_MORE. This loop then preserves the flag on every one-byte send. On Linux, that corking hint allows the kernel to retain these bytes and send them together rather than expose the intended small chunks. Exact flushing and receive boundaries remain kernel- and scheduling-dependent, so this is not proof that every header arrives intact. V2 handshakes and final payload or packet sends without queued successors do not carry the hint, so the experiment is weakened rather than disabled. Clear MSG_MORE on intermediate sub-sends under #ifdef MSG_MORE; it is only a coalescing hint, so removing it preserves stream semantics while avoiding this obstacle to fragmentation.


Optional improvements

Link

[suggestion] · Send-side stress leaves receive fragmentation uncontrolled

A clean run cannot establish arbitrary receive-chunking robustness: reads can coalesce the small sends, and Python-originated P2P and RPC traffic bypasses this change.

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

Details and suggested fix

yield() only increases the chance that the reader runs between sends. Sock::Recv remains a direct wrapper, and the P2P handler still requests up to 64 KiB, so queued bytes can arrive in one read. Python P2P writes use asyncio and Python RPC uses http.client; neither passes through this modified Sock::Send. Existing transport unit and fuzz tests already feed fragmented spans to parsers, but they do not force fragmented socket reads in this integration run. Add a fixed small receive-size cap for stream sockets to exercise node-side readers, including Python-originated traffic. Keep the cap consistent between MSG_PEEK and the following read because RecvUntilTerminator requires that read to consume the length established by the peek. Leave datagram reads unchanged to avoid truncation. If the experiment remains send-only, describe its receive-fragmentation coverage as probabilistic rather than forced.


Link

[suggestion] · The new yield call lacks its direct <thread> dependency

The call currently relies on a transitive include, and IWYU enforcement for util/*.cpp is likely to report an unrelated failure in this stress run.

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

Details and suggested fix

std::this_thread::yield() is declared by <thread>, but this file obtains that header indirectly through util/threadinterrupt.h and sync.h. The developer notes require direct includes, and CI applies IWYU fixes to util/*.cpp and fails if they produce a diff. Add #include <thread> so the new dependency is explicit and does not add unrelated diagnostic noise to the chunking experiment. The IWYU failure is predicted from the source and configuration, not an observed run.


Coverage details