1 minor finding · 1 suggestion
Findings
[minor] · Receive chunking truncates datagrams and can stall mapport shutdown
In manual runs of this diagnostic branch, the cap can discard PCP/NAT-PMP replies and netlink completion messages, causing mapping failures and potentially blocking shutdown rather than exposing stream-chunking bugs.
Location: src/util/sock.cpp:80 (head).
Details and suggested fix
Sock::Recv now caps every socket without checking its type. For a normal small UDP reply, the cap is one byte. On POSIX, that discards the rest of the datagram rather than retaining it for another read. PCP/NAT-PMP validators reject the prefix, including the unsupported-version response needed for NAT-PMP fallback. Fresh replies on retries suffer the same truncation, so the request ends in MappingError::NETWORK_ERROR. The Linux/FreeBSD netlink gateway query also uses SOCK_DGRAM, and its socket remains blocking. If truncation prevents parsing completion and no gateway or other exit is reached first, the next receive can wait indefinitely after the response queue drains. InterruptMapPort cannot wake that receive, while shutdown joins the mapport thread. Restrict the artificial cap to SOCK_STREAM, using SO_TYPE, and pass the caller's length unchanged for other socket types.
Mapping is enabled by default; -natpmp=0 disables it, and -proxy or -listen=0 normally disables it through parameter interactions. Normal unit and functional setups disable mapping, and scripted PCP tests override Recv, so they do not exercise this real-socket path. No manual-run failure was reported. The netlink hang remains conditional on kernel FIONREAD behavior and response layout and has not been reproduced.
Optional improvements
[suggestion] · The standalone socket-test fix is bundled with the reproducer
The receive loop removes a pre-existing TCP assumption independently of the shim, so submitting the test-only commit separately would preserve it when this diagnostic PR closes unmerged.
Location: src/test/sock_tests.cpp:134 (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. The new loop accumulates partial reads while retaining the total-length and payload checks. BOOST_REQUIRE_GT(ret, 0) stops the test on EOF or an error rather than retrying. Submit this test-only commit as a separate PR without the sock.cpp reproducer. Splitting is unlikely for this small synchronous loopback send, so the value is test robustness rather than a fix for reported flakiness.