1 minor finding · 2 suggestions
Findings
[minor] · Forced chunking discards datagram replies and can block shutdown
The reproducer caps UDP and netlink receives as though they were streams, discarding port-mapping replies and potentially preventing shutdown with port mapping enabled on Linux.
Location: src/util/sock.cpp:82 (head).
Details and suggested fix
The first receive with a nonzero caller length requests only one byte, regardless of socket type. A short datagram receive discards the remainder rather than leaving it for another read. On Linux, the additional cap at one third of the next UDP datagram's size keeps normal PCP/NAT-PMP replies unusable, including the reply needed for NAT-PMP fallback. Retries cannot recover discarded bytes; Windows instead reports truncated UDP receives as errors. The Linux gateway query also uses a blocking SOCK_DGRAM netlink socket. If a small route dump is drained in reads shorter than a netlink header, NLMSG_OK never succeeds and the next receive waits without a timeout or interruption check. StopMapPort() then waits for that thread during shutdown. No hang has been observed; this consequence follows statically under that route-dump condition. Manual runs can reach it because -natpmp defaults to true, unless settings such as -proxy or -listen=0 soft-disable it. Standard unit and functional fixtures disable mapping, and PCPTestSock overrides Recv. Restrict the limiter to SOCK_STREAM, for example by caching SO_TYPE, and preserve the caller's length for datagram sockets. These would otherwise be failures introduced by the reproducer, not chunking defects in the datagram callers.
Optional improvements
[suggestion] · The receive-loop fix remains tied to the unmerged reproducer
The test's receive loop handles legal TCP short reads independently of the diagnostic shim, so it is worth preserving in a separate PR.
Location: src/test/sock_tests.cpp:132 (head).
Details and suggested fix
Base TcpSocketPair::send_and_receive() expects one Recv() to return the entire four-byte send, which TCP does not guarantee even on loopback. The new loop collects positive reads until the message is complete, retains the length and payload assertions, and fails immediately on EOF or error. This is a standalone test-robustness improvement, not evidence of frequent failures on base. Since this diagnostic PR is intended to close unmerged, submit the second commit separately without the sock.cpp reproducer.
[suggestion] · Mock-socket unit tests bypass the forced receive chunking
Mock-backed I2P and HTTP unit tests bypass the new limiter, so their results do not measure this run's additional forced chunking.
Location: src/util/sock.cpp:58 (head).
Details and suggested fix
StaticContentsSock::Recv() and DynSock::Recv(), through Pipe::GetBytes(), override the changed base method and return all buffered data up to len. The I2P tests install the former, while SocketTestingSetup supplies the latter for HTTP socket tests. Document these exclusions when reporting the run's results, or apply the limiter to those stream mocks using their buffered size as availability. A mock limiter must preserve EOF/EAGAIN behavior and peek/consume consistency because RecvUntilTerminator() requires the consuming read to return the requested bytes reported by its peek. Keep datagram mocks such as PCPTestSock unfragmented. This is a gap in the diagnostic run's additional coverage, not an absence of segmentation testing: HTTP already has partial-input tests, FuzzedSock supplies variable-length reads, and real-socket functional tests exercise the shim.