mirror of
https://github.com/retoaccess1/haveno-reto.git
synced 2024-11-10 05:03:35 +01:00
fix error on shut down broadcasting to peers
This commit is contained in:
parent
8ce91aa0c1
commit
ec9f91e014
@ -38,6 +38,7 @@ import com.google.common.util.concurrent.SettableFuture;
|
|||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
import javafx.beans.property.ReadOnlyObjectProperty;
|
import javafx.beans.property.ReadOnlyObjectProperty;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@ -82,7 +83,8 @@ public abstract class NetworkNode implements MessageListener {
|
|||||||
private final ListeningExecutorService sendMessageExecutor;
|
private final ListeningExecutorService sendMessageExecutor;
|
||||||
private Server server;
|
private Server server;
|
||||||
|
|
||||||
private volatile boolean shutDownInProgress;
|
@Getter
|
||||||
|
private volatile boolean isShutDownStarted;
|
||||||
// accessed from different threads
|
// accessed from different threads
|
||||||
private final CopyOnWriteArraySet<OutboundConnection> outBoundConnections = new CopyOnWriteArraySet<>();
|
private final CopyOnWriteArraySet<OutboundConnection> outBoundConnections = new CopyOnWriteArraySet<>();
|
||||||
protected final ObjectProperty<NodeAddress> nodeAddressProperty = new SimpleObjectProperty<>();
|
protected final ObjectProperty<NodeAddress> nodeAddressProperty = new SimpleObjectProperty<>();
|
||||||
@ -181,7 +183,7 @@ public abstract class NetworkNode implements MessageListener {
|
|||||||
try {
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
if (!shutDownInProgress) {
|
if (!isShutDownStarted) {
|
||||||
log.error("Error at closing socket " + throwable);
|
log.error("Error at closing socket " + throwable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,8 +364,8 @@ public abstract class NetworkNode implements MessageListener {
|
|||||||
|
|
||||||
public void shutDown(Runnable shutDownCompleteHandler) {
|
public void shutDown(Runnable shutDownCompleteHandler) {
|
||||||
log.info("NetworkNode shutdown started");
|
log.info("NetworkNode shutdown started");
|
||||||
if (!shutDownInProgress) {
|
if (!isShutDownStarted) {
|
||||||
shutDownInProgress = true;
|
isShutDownStarted = true;
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
server.shutDown();
|
server.shutDown();
|
||||||
server = null;
|
server = null;
|
||||||
|
@ -352,7 +352,13 @@ public class BroadcastHandler implements PeerManager.Listener {
|
|||||||
|
|
||||||
sendMessageFutures.stream()
|
sendMessageFutures.stream()
|
||||||
.filter(future -> !future.isCancelled() && !future.isDone())
|
.filter(future -> !future.isCancelled() && !future.isDone())
|
||||||
.forEach(future -> future.cancel(true));
|
.forEach(future -> {
|
||||||
|
try {
|
||||||
|
future.cancel(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!networkNode.isShutDownStarted()) throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
sendMessageFutures.clear();
|
sendMessageFutures.clear();
|
||||||
|
|
||||||
peerManager.removeListener(this);
|
peerManager.removeListener(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user