1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 10:37:59 +01:00

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

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);