The sock_tests/send_and_receive unit test can fail in the -- improbable -- case when network reads happen to arrive in smaller chunks.
Related to #36726 .
All networking code using sockets must not make assumption about the chunking of the incoming/outgoing data, and should be resilient against any chunking.
This test expects to read 4 bytes from the socket, and it expects that to happen in one Recv() call. However, there is no guarantee that data arrives in one call.
This was found -- and can be reproduced -- by using a reproducer patch, that forces all socket sends to use smaller chunking. For the run with the reproducer see #36751 .
The issue is test-code only, the non-test code is correct.
The fix is to replace the single Recv call with one or more repeated calls, until the expected amount of data is read, and do the checks only afterwards.
This fix makes the test more robust, even though a failure due to this issue in CI is very unlikely, but not impossible.