Do not re-use the Socket after connect() failed

Fixes SMACK-724.
This commit is contained in:
Florian Schmaus 2016-06-19 12:06:21 +02:00
parent f8c00533c7
commit 73fcbc6b27
1 changed files with 4 additions and 1 deletions

View File

@ -554,7 +554,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
if (socketFactory == null) {
socketFactory = SocketFactory.getDefault();
}
socket = socketFactory.createSocket();
for (HostAddress hostAddress : hostAddresses) {
Iterator<InetAddress> inetAddresses = null;
String host = hostAddress.getFQDN();
@ -575,6 +574,10 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
continue;
}
innerloop: while (inetAddresses.hasNext()) {
// Create a *new* Socket before every connection attempt, i.e. connect() call, since Sockets are not
// re-usable after a failed connection attempt. See also SMACK-724.
socket = socketFactory.createSocket();
final InetAddress inetAddress = inetAddresses.next();
final String inetAddressAndPort = inetAddress + " at port " + port;
LOGGER.finer("Trying to establish TCP connection to " + inetAddressAndPort);