Repository navigation
Description
Summary: A test run with a forced reproducer, with changed socket data send chunking discovered issues with a few tests.
All networking code using sockets must not make assumption about the chunking of the incoming/outgoing data, and should be resilient against any chunking. Normally, the chunking of the sends of the writer dictate the chunking of the receives at the reader, but this is not guaranteed by IP/TCP, intermediate networking elements may change the packet structure. In test using sockets on the same host, this is not very likely, but still possible.
A test run was executed with a stress test reproducer. For every socket send, sending was changed to break up data in small chunks. This forcedly changed chunking of the data stream. This way code was tested for robustness in face of unexpected chunking of the data.
The run is here: #36724 , the reproducer can be seen here .
A few test failed, which where analyzed.
On the positive note, NO NON-TEST ISSUES were identified.
The list of failed tests with the failure root cause:
Failed tests:
-
interface_http.py-- Failed in several CI runs. A wrong assumption in the test; it is implicitly assumed that an HTTP response arrives in a singlerecv. Being fixed, test: interface_http: Fix for case when a response doesn't arrive in one recv #36729 . -
rpc_setban.py --v2transportFailed in two CI runs (1 2). The reason is more subtle, the tested use case can have two outcomes, depending on weather a full key (64 bytes) could be sent on a closing connection or not (ShouldReconnectV1()). The second case is very unlikely, but still can happen. The test is only prepared for the first outcome, with the reproduces the second can happen, causing it to fail. Up for discussion whether should be fixed or kept as-is. -
p2p_v2_encrypted.py-- Failed once, a time-out occurred (on Windows). Also related to v1/v2 transport selection (ShouldReconnectV1()), but the reason is in the test framework (p2p.py, 358-361). The Python v1 peer disconnects after reading 4 bytes. If they are sent in separate syscalls, the sender node will not be able to send all 64 key bytes. This will causeShouldReconnectV1()to return false, and the node will not reconnect. The test waits on reconnect. A potential fix is to change Python v1 parser to behave like bitcoind by moving the magic check after the full-header length check. Fix is attempted in test: p2p: check v1 magic bytes only after the full header #36730 .
A note regarding chance of occurrence. When a test makes an assumption about data chunking (1.), it can pass reliably in CI runs and local tests. However, this is still a latent bug, as there is no guarantee for correct execution. Data chunking can change between sender and receiver. So the fix is recommended, to make the test more resilient, but the issue is low priority.
Activity
optout21 commentedon Nov 2, 2026
PR #36729 raised to fix
interface_http.optout21 commentedon Nov 2, 2026
PR #36730 raised to fix
p2p_v2_encrypted.py, with a small change to the test framework p2p v1 peer.optout21 commentedon Nov 5, 2026
A similar reproducer run was executed, with receiver-side forced chunking of data: #36751 .
Test failures identified there, with some CI runs where they failed, are:
sock_tests/send_and_receiveunit test. A unit test failure prevented execution of the integration tests, so a fix was included in the reproducer PR as well. It still fails in the per-commit checks log.interface_http.pyFailed many times. Three logs are included here: 1 2 3.feature_torcontrol.pyFailed in two windows tests (1 2)Pranav-error commentedon Nov 12, 2026
While going through the socket-chunking cases here, I noticed another spot that assumes a
recv()-boundary-independent marker count, in a method not covered by #36729: the response-drain loop at the end ofcheck_slow_read_throttleintest/functional/interface_http.py:response.count(b"HTTP/1.1 200")is evaluated on each individualrecv()chunk. If arecv()boundary splits theHTTP/1.1 200marker across two chunks (e.g. one ends...HTTP/1., the next starts1 200...), it is counted in neither, sonum_resundercounts and the loop can't reachcount + 2, blocking until the socket timeout. A ~10 MB drain is quite likely to span multiplerecv()calls, so this looks like the same latent class.Counting over the accumulated buffer avoids the split-marker case:
Found by inspection; I haven't run it under the forced-chunking reproducer. Happy to open a PR if it's useful and not already covered elsewhere.
optout21 commentedon Nov 12, 2026
Thanks, I will check. It can be included in #36729, if you agree.
Pranav-error commentedon Nov 12, 2026
Sounds good, please include it in #36729.
The minimal change is to accumulate into a buffer and count over everything received so far, so a marker split across a
recv()boundary is still counted once both halves arrive:Happy to open a separate PR instead if you'd rather keep #36729 focused — whichever is easier for you.
optout21 commentedon Nov 18, 2026
Thanks for looking into this. I looked at it now, and as I see, a fix has been already applied.
You're right that the original drain loop had the same problem: counting
HTTP/1.1 200in eachrecv()chunk misses a marker that's split across two chunks. It also spun forever onEOF, sincerecv()keeps returningb"".The fix is already in the PR (and has been with its first version). The last hunk of
568d8f23edreplaces that loop withrecv_responses(count + 2). That helper collects into one buffer and frames each response byContent-Length, so it doesn't depend on whererecv()splits the data, and it stops when the connection closes. TheHTTP/1.1 200count is then taken over the whole buffer and checked withassert_greater_than_or_equal(num_res, count + 2). So no separate PR is needed, but please do re-check if you wish.Pranav-error commentedon Nov 20, 2026
Thank you @optout21!
darosior commentedon Nov 24, 2026
Ran into this when porting macOS to using poll. On macOS, after node1's FIN, poll() reports POLLHUP and no longer POLLOUT, so node0's socket wait doesn't return a SendEvent. node0 reads EOF without having sent anything, and
ShouldReconnectV1()returns false. (cc @theuni)The switch to poll() exacerbated this behaviour, but the test is inherently racy, so i think it's worth fixing.
fanquake commentedon Nov 25, 2026
cc @pinheadmz