Alternative approach to #36688, citing the relevant parts of its description:
There is currently nothing preventing us to receive TCP urgent data, which would never be returned by
recv(). Linux'spoll()is indifferent to this, but theselect()socket monitoring may keep reporting it as pending on some platforms.This would not prevent progress nor lead to a crash anymore after #36665, but it's still undesirable.
Fix this by only adding a socket to the select() exception set while waiting for a non-blocking connect() to complete. Windows needs that to detect a failed connection. Established connections no longer monitor the exception set on any platform. This approach was suggested by theuni in #36716 (comment) and replaces the earlier version of this PR, which ignored the exception set outside Windows and disconnected on it on Windows.
We could instead have set SO_OOBINLINE on our sockets, so recv() returns any urgent data sent to us (and likely leads us to disconnect the peer). RFC 6093 doesn't forbid this, but the current approach seems more clear and direct to me.
The PR makes one additional change for clarity: if errorSet is reported for a socket we did not request to read from, disconnect directly instead of first attempting a send that would fail (emits a different log message). if (recvSet || errorSet) is left as is. Since select() no longer reports errors for established connections, this only applies to poll().
Test coverage is introduced in p2p_socket_errors.py.
Finally the same early error check is applied to HTTP, with urgent data coverage in interface_http.py.