diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index 582c0d70..4dfbffc5 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -1271,6 +1271,8 @@ public abstract class Trade implements Tradable, Model { // shut down trade threads synchronized (this) { + isInitialized = false; + isShutDown = true; List shutDownThreads = new ArrayList<>(); shutDownThreads.add(() -> ThreadUtils.shutDown(getId())); shutDownThreads.add(() -> ThreadUtils.shutDown(getConnectionChangedThreadId())); @@ -1305,8 +1307,6 @@ public abstract class Trade implements Tradable, Model { } // de-initialize - isInitialized = false; - isShutDown = true; if (idlePayoutSyncer != null) { xmrWalletService.removeWalletListener(idlePayoutSyncer); idlePayoutSyncer = null; diff --git a/core/src/main/java/haveno/core/trade/protocol/TradeProtocol.java b/core/src/main/java/haveno/core/trade/protocol/TradeProtocol.java index ee044ea5..3e761334 100644 --- a/core/src/main/java/haveno/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/haveno/core/trade/protocol/TradeProtocol.java @@ -469,8 +469,10 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D public void handle(DepositsConfirmedMessage response, NodeAddress sender) { System.out.println(getClass().getSimpleName() + ".handle(DepositsConfirmedMessage)"); + if (!trade.isInitialized() || trade.isShutDown()) return; ThreadUtils.execute(() -> { synchronized (trade) { + if (!trade.isInitialized() || trade.isShutDown()) return; latchTrade(); this.errorMessageHandler = null; expect(new Condition(trade) @@ -496,6 +498,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D // received by seller and arbitrator protected void handle(PaymentSentMessage message, NodeAddress peer) { System.out.println(getClass().getSimpleName() + ".handle(PaymentSentMessage)"); + if (!trade.isInitialized() || trade.isShutDown()) return; if (!(trade instanceof SellerTrade || trade instanceof ArbitratorTrade)) { log.warn("Ignoring PaymentSentMessage since not seller or arbitrator"); return; @@ -507,6 +510,7 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D // TODO A better fix would be to add a listener for the wallet sync state and process // the mailbox msg once wallet is ready and trade state set. synchronized (trade) { + if (!trade.isInitialized() || trade.isShutDown()) return; if (trade.getPhase().ordinal() >= Trade.Phase.PAYMENT_SENT.ordinal()) { log.warn("Received another PaymentSentMessage which was already processed, ACKing"); handleTaskRunnerSuccess(peer, message); @@ -548,12 +552,14 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D private void handle(PaymentReceivedMessage message, NodeAddress peer, boolean reprocessOnError) { System.out.println(getClass().getSimpleName() + ".handle(PaymentReceivedMessage)"); + if (!trade.isInitialized() || trade.isShutDown()) return; ThreadUtils.execute(() -> { if (!(trade instanceof BuyerTrade || trade instanceof ArbitratorTrade)) { log.warn("Ignoring PaymentReceivedMessage since not buyer or arbitrator"); return; } synchronized (trade) { + if (!trade.isInitialized() || trade.isShutDown()) return; latchTrade(); Validator.checkTradeId(processModel.getOfferId(), message); processModel.setTradeMessage(message);