Skip to content

Commit

Permalink
Merge pull request #5151 from olegmoz/5150-zero-connection-timeout
Browse files Browse the repository at this point in the history
Issue #5150 - Infinite connection timeout support in ManagedSelector
  • Loading branch information
sbordet committed Aug 14, 2020
2 parents edbc193 + 32fe19a commit a6e1f9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -690,7 +690,7 @@ public void setName(String name)
}

/**
* @return the max time, in milliseconds, a connection can take to connect to destinations
* @return the max time, in milliseconds, a connection can take to connect to destinations. Zero value means infinite timeout.
*/
@ManagedAttribute("The timeout, in milliseconds, for connect() operations")
public long getConnectTimeout()
Expand All @@ -699,7 +699,7 @@ public long getConnectTimeout()
}

/**
* @param connectTimeout the max time, in milliseconds, a connection can take to connect to destinations
* @param connectTimeout the max time, in milliseconds, a connection can take to connect to destinations. Zero value means infinite timeout.
* @see java.net.Socket#connect(SocketAddress, int)
*/
public void setConnectTimeout(long connectTimeout)
Expand Down
Expand Up @@ -888,7 +888,11 @@ class Connect implements SelectorUpdate, Runnable
{
this.channel = channel;
this.attachment = attachment;
this.timeout = ManagedSelector.this._selectorManager.getScheduler().schedule(this, ManagedSelector.this._selectorManager.getConnectTimeout(), TimeUnit.MILLISECONDS);
long timeout = ManagedSelector.this._selectorManager.getConnectTimeout();
if (timeout > 0)
this.timeout = ManagedSelector.this._selectorManager.getScheduler().schedule(this, timeout, TimeUnit.MILLISECONDS);
else
this.timeout = null;
}

@Override
Expand Down Expand Up @@ -919,7 +923,8 @@ public void failed(Throwable failure)
{
if (failed.compareAndSet(false, true))
{
timeout.cancel();
if (timeout != null)
timeout.cancel();
IO.close(channel);
ManagedSelector.this._selectorManager.connectionFailed(channel, failure, attachment);
}
Expand Down

0 comments on commit a6e1f9d

Please sign in to comment.