okhttp: Set socket read timeout during TLS handshake - #13081
Open
ArturoSalazarB16 wants to merge 5 commits into
Open
ArturoSalazarB16 wants to merge 5 commits into
ArturoSalazarB16 wants to merge 5 commits into
Conversation
In `OkHttpClientTransport`, direct TLS connection setup calls `OkHttpTlsUpgrader.upgrade(...)` without configuring a socket read timeout (`setSoTimeout`). When a middlebox or unresponsive server completes the TCP three-way handshake and acknowledges the TLS `ClientHello` without sending a `ServerHello` or `RST`, `sslSocket.startHandshake()` blocks indefinitely in socket read. Because `this.socket` and `asyncSink` are only assigned after `OkHttpTlsUpgrader.upgrade(...)` returns, channel shutdown cannot close the underlying socket either, leaving the subchannel permanently stuck in `CONNECTING`. Configure `sock.setSoTimeout(proxySocketTimeout)` before `OkHttpTlsUpgrader.upgrade(...)` and reset it to `0` once the TLS upgrade completes, matching the timeout handling in `createHttpProxySocket`. Also close `sock` via `GrpcUtil.closeQuietly(sock)` in `catch (Exception e)` so the socket is not leaked when handshake setup fails before `asyncSink.becomeConnected(...)` takes ownership.
|
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
OkHttpClientTransport, direct TLS connection setup callsOkHttpTlsUpgrader.upgrade(...)without configuring a socket read timeout (setSoTimeout). When a middlebox or unresponsive server completes the TCP three-way handshake and acknowledges the TLSClientHellowithout sending aServerHelloorRST,sslSocket.startHandshake()blocks indefinitely in socket read. Becausethis.socketandasyncSinkare only assigned afterOkHttpTlsUpgrader.upgrade(...)returns, channel shutdown cannot close the underlying socket either, leaving the subchannel permanently stuck inCONNECTING. Configuresock.setSoTimeout(proxySocketTimeout)beforeOkHttpTlsUpgrader.upgrade(...)and reset it to0once the TLS upgrade completes, matching the timeout handling increateHttpProxySocket. Also closesockviaGrpcUtil.closeQuietly(sock)incatch (Exception e)so the socket is not leaked when handshake setup fails beforeasyncSink.becomeConnected(...)takes ownership.