Review report

core: PR #36688

2 suggestions

Optional improvements

Link

[suggestion] · Urgent pointers ahead of received data can still cause a busy loop

On macOS and BSD, a crafted peer can keep the select-based handler waking without data to read; the behavior is not a regression, but the change only addresses urgent bytes that have arrived.

Location: src/netbase.cpp:573 (head).

Details and suggested fix

On non-Linux builds, Sock::WaitMany uses select() and puts sockets monitored for reads in the exception set. On FreeBSD and XNU, that set can report the receive-side urgent mark. SO_OOBINLINE controls whether the urgent byte stays in the normal stream; it does not prevent the mark from being reported when the urgent pointer is ahead of received data.

When the urgent byte has arrived, reading it inline clears the mark. But TCP allows the urgent pointer to point beyond the data in a segment. A peer that crafts segments, for example with raw sockets, can send a small payload with the urgent pointer up to 64 KiB ahead and then withhold the intervening bytes. select() can continue reporting an exception while recv() has nothing to return. SocketHandlerConnected gets WSAEWOULDBLOCK from Recv() and keeps the peer, so the next WaitMany returns immediately and the net thread loops without its 50 ms wait. Peer servicing continues; the potential cost is CPU use and extra lock traffic. The code establishes this behavior for that conditional input, but no concrete production trigger or affected caller was identified; the kernel behavior is based on FreeBSD and XNU source and should be confirmed on macOS or FreeBSD.

Restricting FD_SET(s, &err) to WIN32 would avoid this case. The exception set is needed on Windows to detect failed nonblocking connects, and Windows does not report OOB data in exceptfds once SO_OOBINLINE is set. On POSIX, ConnectToSocket detects failed connects through writability and SO_ERROR. If that change is out of scope, narrow the new comment to urgent data that has arrived.


Link

[suggestion] · Urgent-data test does not check that the pending state clears

The test verifies inline delivery but would not catch a platform that continues reporting an exception after the byte is consumed.

Location: src/test/netbase_tests.cpp:658 (head).

Details and suggested fix

The new CreateSockOS comment gives persistent urgent-data reporting as the reason for setting SO_OOBINLINE. The test sends one MSG_OOB byte, waits once, and checks that Recv() returns it, but does not wait again after consuming the byte. A platform that delivers the byte inline while still flagging an exception in select() would pass. After the final check, add a short-timeout sock->Wait(..., Sock::RecvEvent, &occurred) and check that occurred is zero. The client sends nothing else, so the result is deterministic. This check is vacuous on Linux, whose poll backend does not request POLLPRI, but exercises the select exception set on macOS and Windows CI. It covers only the case where the urgent byte has arrived.


Coverage details