net: stop using a socket once a wait reports an error

bitcoin/bitcoin: PR #36953

1 suggestion

Optional improvements

Link

[suggestion] · Socket mocks leave ErrorEvent precedence untested

The existing socket doubles do not inject ErrorEvent, leaving their tests unable to distinguish immediate disconnection from continued I/O when an error accompanies readiness.

Location: src/net.cpp:2219 (head).

Details and suggested fix

ZeroSock and FuzzedSock copy requested readiness or return zero, and DynSock generates only RecvEvent and SendEvent. Even http_socket_error_tests injects a recoverable Send() failure rather than a wait-reported error. Extend the mock wait machinery to inject ErrorEvent alone and alongside readiness. Assert that the HTTP connection is marked for disconnection without receiving or dispatching a request, and that ConnMan closes the node without sending or receiving. A paused-receive P2P fixture needs pending output so GenerateWaitSockets() includes it.

For SendComplete() and RecvUntilTerminator(), let the initial optimistic I/O return a would-block error, then have Wait() report ErrorEvent. Assert the new Socket error exception and no subsequent I/O. A real-socket reset followed only by an exception assertion is insufficient: both helpers already threw on permanent I/O errors before this change, so that test could pass without reaching either new check.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Unresolved disagreements

The inspected historical record presents competing policies rather than a settled requirement: treat readiness as a hint and preserve opportunities to drain or finish sending, versus fail closed on non-readiness events. Participants also questioned whether select exceptions reliably identify hostile urgent data or could reflect unrelated platform conditions.

The immediate-disconnect change selects the fail-closed side of this tradeoff. The historical compatibility questions are therefore whether useful buffered traffic is intentionally forfeited on hangup and whether exceptional readiness is sufficiently specific to justify termination—not simply whether an event named ErrorEvent should be considered fatal. The inspected passages do not establish a final resolution.

Source 1 · Source 2 · Source 3 · Source 4 · Source 5