diff --git a/domain/src/main/java/ch/dissem/bitmessage/BitmessageContext.java b/domain/src/main/java/ch/dissem/bitmessage/BitmessageContext.java index 1e4e905..d3a1329 100644 --- a/domain/src/main/java/ch/dissem/bitmessage/BitmessageContext.java +++ b/domain/src/main/java/ch/dissem/bitmessage/BitmessageContext.java @@ -206,7 +206,8 @@ public class BitmessageContext { try { t.join(); } catch (InterruptedException e) { - throw new RuntimeException(e.getMessage(), e); + LOG.info("Thread was interrupted. Trying to shut down synchronization and returning."); + t.interrupt(); } } } diff --git a/domain/src/main/java/ch/dissem/bitmessage/ports/NetworkHandler.java b/domain/src/main/java/ch/dissem/bitmessage/ports/NetworkHandler.java index fd44358..2c79b1f 100644 --- a/domain/src/main/java/ch/dissem/bitmessage/ports/NetworkHandler.java +++ b/domain/src/main/java/ch/dissem/bitmessage/ports/NetworkHandler.java @@ -29,6 +29,9 @@ import java.net.InetAddress; public interface NetworkHandler { /** * Connects to the trusted host, fetches and offers new messages and disconnects afterwards. + *
+ * An implementation should disconnect if either the timeout is reached or the returned thread is interrupted. + *
*/ Thread synchronize(InetAddress trustedHost, int port, MessageListener listener, long timeoutInSeconds); diff --git a/networking/src/main/java/ch/dissem/bitmessage/networking/Connection.java b/networking/src/main/java/ch/dissem/bitmessage/networking/Connection.java index f0ff5ed..b2c2e40 100644 --- a/networking/src/main/java/ch/dissem/bitmessage/networking/Connection.java +++ b/networking/src/main/java/ch/dissem/bitmessage/networking/Connection.java @@ -130,6 +130,9 @@ public class Connection { @SuppressWarnings("RedundantIfStatement") private boolean syncFinished(NetworkMessage msg) { + if (Thread.interrupted()) { + return true; + } if (syncTimeout == 0 || state != ACTIVE) { return false; }