Improve shutdown of Network.

Detect interrupt during peer connect so we can return without trying
to set up new peer.

Do join() after interrupt() in Network.shutdown.
This commit is contained in:
catbref 2019-06-18 11:16:59 +01:00
parent c68e0eb6ea
commit 84f5935d38

View File

@ -362,6 +362,9 @@ public class Network extends Thread {
if (!newPeer.connect()) if (!newPeer.connect())
return; return;
if (this.isInterrupted())
return;
synchronized (this.connectedPeers) { synchronized (this.connectedPeers) {
this.connectedPeers.add(newPeer); this.connectedPeers.add(newPeer);
} }
@ -824,6 +827,11 @@ public class Network extends Thread {
peerExecutor.shutdownNow(); peerExecutor.shutdownNow();
this.interrupt(); this.interrupt();
try {
this.join();
} catch (InterruptedException e) {
// We were interrupted while waiting for thread to join
}
} }
} }