From fb55b9065f233e0b0dfc75df65d235dc43ea29ac Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 19 Jun 2016 12:06:21 +0200 Subject: [PATCH] Do not re-use the Socket after connect() failed Fixes SMACK-724. --- .../java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 8a1d6e5a1..d0ca18bf2 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -579,6 +579,10 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { throw new UnknownHostException(host); } 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);