[Private Network Access] Avoid notifying about closed socket.
This can happen due to the following race in the network code:
1. Socket is re-used from socket pools, `SocketPosix::IsConnected()`
returns true.
2. Remote side closes the socket.
3. `HttpStream::GetRemoteEndpoint()` fails during
`HttpNetworkTransaction::DoConnectedCallback()` because the socket is
not connected anymore
The race caused flakiness when establishing connections to non-public
servers that do not serve `Connection: close` headers yet support only a
single request per socket. This is the case for some web platform tests.
Tested this manually by running the flaky test 5000 times with no
flakes. Previously it would fail once every couple hundred times fairly
reliably.
Fixed: chromium:1322072
Change-Id: I8cdbf52d04cbec3f52a1d3e0a8a7779bd4346605
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3652198
Reviewed-by: David Benjamin <[email protected]>
Auto-Submit: Titouan Rigoudy <[email protected]>
Commit-Queue: Titouan Rigoudy <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1005811}
diff --git a/net/websockets/websocket_basic_handshake_stream.cc b/net/websockets/websocket_basic_handshake_stream.cc
index d72fe99..2b20820 100644
--- a/net/websockets/websocket_basic_handshake_stream.cc
+++ b/net/websockets/websocket_basic_handshake_stream.cc
@@ -363,11 +363,11 @@
parser()->GetSSLCertRequestInfo(cert_request_info);
}
-bool WebSocketBasicHandshakeStream::GetRemoteEndpoint(IPEndPoint* endpoint) {
+int WebSocketBasicHandshakeStream::GetRemoteEndpoint(IPEndPoint* endpoint) {
if (!state_.connection() || !state_.connection()->socket())
- return false;
+ return ERR_SOCKET_NOT_CONNECTED;
- return state_.connection()->socket()->GetPeerAddress(endpoint) == OK;
+ return state_.connection()->socket()->GetPeerAddress(endpoint);
}
void WebSocketBasicHandshakeStream::PopulateNetErrorDetails(