358147: SelectConnector catch UnresolvedAddressException to avoid socket leak

This commit is contained in:
Thomas Becker 2011-09-20 10:20:24 +02:00 committed by Jesse McConnell
parent f0fe55165b
commit 4b7f8d79dd
1 changed files with 11 additions and 1 deletions

View File

@ -17,8 +17,10 @@ import java.io.IOException;
import java.net.SocketTimeoutException;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.nio.channels.UnresolvedAddressException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSession;
@ -104,7 +106,15 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector
else
{
channel.configureBlocking(false);
channel.connect(address.toSocketAddress());
try
{
channel.connect(address.toSocketAddress());
}
catch (UnresolvedAddressException ex)
{
channel.close();
throw ex;
}
_selectorManager.register(channel,destination);
ConnectTimeout connectTimeout = new ConnectTimeout(channel,destination);
_httpClient.schedule(connectTimeout,_httpClient.getConnectTimeout());