Skip to content

Commit

Permalink
fix error on shut down broadcasting to peers
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jul 1, 2024
1 parent 8ce91aa commit ec9f91e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 6 additions & 4 deletions p2p/src/main/java/haveno/network/p2p/network/NetworkNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import lombok.Getter;

import java.net.ServerSocket;
import java.net.Socket;
Expand Down Expand Up @@ -82,7 +83,8 @@ public abstract class NetworkNode implements MessageListener {
private final ListeningExecutorService sendMessageExecutor;
private Server server;

private volatile boolean shutDownInProgress;
@Getter
private volatile boolean isShutDownStarted;
// accessed from different threads
private final CopyOnWriteArraySet<OutboundConnection> outBoundConnections = new CopyOnWriteArraySet<>();
protected final ObjectProperty<NodeAddress> nodeAddressProperty = new SimpleObjectProperty<>();
Expand Down Expand Up @@ -181,7 +183,7 @@ public SettableFuture<Connection> sendMessage(@NotNull NodeAddress peersNodeAddr
try {
socket.close();
} catch (Throwable throwable) {
if (!shutDownInProgress) {
if (!isShutDownStarted) {
log.error("Error at closing socket " + throwable);
}
}
Expand Down Expand Up @@ -362,8 +364,8 @@ public Set<NodeAddress> getNodeAddressesOfConfirmedConnections() {

public void shutDown(Runnable shutDownCompleteHandler) {
log.info("NetworkNode shutdown started");
if (!shutDownInProgress) {
shutDownInProgress = true;
if (!isShutDownStarted) {
isShutDownStarted = true;
if (server != null) {
server.shutDown();
server = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,13 @@ private void cleanup() {

sendMessageFutures.stream()
.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();

peerManager.removeListener(this);
Expand Down

0 comments on commit ec9f91e

Please sign in to comment.