-
Notifications
You must be signed in to change notification settings - Fork 666
Fix reconnection hang on HTTP proxy connect failures and stalled handshakes #1275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,25 +252,116 @@ private void connect() { | |
| } | ||
|
|
||
| private void pollConnectFuture() { | ||
| ConnectFuture future = connectFuture; | ||
| if (future == null) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| connectFuture.awaitUninterruptibly(CONNECT_POLL_TIMEOUT); | ||
| if (connectFuture.getSession() != null) { | ||
| ioSession = connectFuture.getSession(); | ||
| future.awaitUninterruptibly(CONNECT_POLL_TIMEOUT); | ||
|
|
||
| IoSession session = future.getSession(); | ||
| if (session != null) { | ||
| ioSession = session; | ||
| connectionFailureCount = 0; | ||
| nextSocketAddressIndex = 0; | ||
| lastConnectTime = System.currentTimeMillis(); | ||
| connectFuture = null; | ||
| } else { | ||
| fixSession.getLog().onEvent( | ||
| return; | ||
| } | ||
|
|
||
| Throwable exception = future.getException(); | ||
| if (exception != null) { | ||
| connectFuture = null; | ||
|
|
||
| /* | ||
| * Do not call cancelPendingConnectAttempt() here. | ||
| * The future already completed with an exception. | ||
| * Just release our reference to the connector. | ||
| */ | ||
|
|
||
| handleConnectException(exception); | ||
| return; | ||
| } | ||
| long now = System.currentTimeMillis(); | ||
| long pendingMillis = now - lastReconnectAttemptTime; | ||
|
|
||
| fixSession.getLog().onEvent( | ||
| "Pending connection not established after " | ||
| + (System.currentTimeMillis() - lastReconnectAttemptTime) | ||
| + pendingMillis | ||
| + " ms."); | ||
|
|
||
| long maxPendingMillis = connectTimeoutMillis; | ||
|
|
||
| if (maxPendingMillis > 0 && pendingMillis >= maxPendingMillis) { | ||
| fixSession.getLog().onEvent( | ||
| "Pending connection exceeded max wait of " | ||
| + maxPendingMillis | ||
| + " ms; cancelling connect attempt and allowing reconnect." | ||
| ); | ||
|
|
||
| try { | ||
| cancelAndResetPendingConnectAttempt(future); | ||
| } catch (Throwable cancelException) { | ||
| fixSession.getLog().onEvent( | ||
| "Exception while cancelling pending connect future: " | ||
| + cancelException | ||
| ); | ||
| } | ||
|
|
||
| /* | ||
| * Important: | ||
| * Reset reconnect timing from this failure moment. | ||
| * Without this, the next timer tick may reconnect immediately | ||
| * because pendingMillis has already exceeded ReconnectInterval. | ||
| */ | ||
| lastConnectTime = now; | ||
| lastReconnectAttemptTime = now; | ||
|
|
||
| handleConnectException(new IOException( | ||
| "Connect attempt exceeded max pending time of " + maxPendingMillis + " ms" | ||
| )); | ||
| } | ||
|
|
||
| } catch (Throwable e) { | ||
| handleConnectException(e); | ||
| } | ||
| } | ||
|
|
||
| synchronized private void cancelAndResetPendingConnectAttempt(ConnectFuture future) throws ConfigError, GeneralSecurityException { | ||
| try { | ||
| if (future != null) { | ||
| IoSession session = future.getSession(); | ||
| if (session != null) { | ||
| session.closeNow(); | ||
| } | ||
|
|
||
| future.cancel(); | ||
| } | ||
| } catch (Throwable e) { | ||
| fixSession.getLog().onEvent( | ||
|
chrjohn marked this conversation as resolved.
Outdated
|
||
| "Exception while cancelling pending connect future: " + e | ||
| ); | ||
| } | ||
|
|
||
| if (ioConnector instanceof ProxyConnector) { | ||
| try { | ||
| ((ProxyConnector) ioConnector).cancelConnectFuture(); | ||
| } catch (Throwable e) { | ||
| fixSession.getLog().onEvent( | ||
| "Exception while cancelling proxy connector future: " + e | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| setupIoConnector(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this only done on a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got this exception when reused IoConnector for proxy. This exception does not occure when reusing the IoConnector in non-proxy connection timeout, where the server does not reply TCP SYN. |
||
| } catch (Throwable e) { | ||
| fixSession.getLog().onEvent("Exception while recreating proxy connector: " + e); | ||
| throw e; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void handleConnectException(Throwable e) { | ||
| ++connectionFailureCount; | ||
| SocketAddress socketAddress = socketAddresses[getCurrentSocketAddressIndex()]; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.