Skip to content

Commit

Permalink
skip trade protocol message processing if shutting down
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jan 24, 2024
1 parent e4e8f5d commit 19d3e28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/haveno/core/trade/Trade.java
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,8 @@ public void shutDown() {

// shut down trade threads
synchronized (this) {
isInitialized = false;
isShutDown = true;
List<Runnable> shutDownThreads = new ArrayList<>();
shutDownThreads.add(() -> ThreadUtils.shutDown(getId()));
shutDownThreads.add(() -> ThreadUtils.shutDown(getConnectionChangedThreadId()));
Expand Down Expand Up @@ -1305,8 +1307,6 @@ public void shutDown() {
}

// de-initialize
isInitialized = false;
isShutDown = true;
if (idlePayoutSyncer != null) {
xmrWalletService.removeWalletListener(idlePayoutSyncer);
idlePayoutSyncer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,10 @@ public void handleDepositResponse(DepositResponse response, NodeAddress sender)

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)
Expand All @@ -496,6 +498,7 @@ public void handle(DepositsConfirmedMessage response, NodeAddress sender) {
// 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;
Expand All @@ -507,6 +510,7 @@ protected void handle(PaymentSentMessage message, NodeAddress peer) {
// 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);
Expand Down Expand Up @@ -548,12 +552,14 @@ protected void handle(PaymentReceivedMessage message, NodeAddress peer) {

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);
Expand Down

0 comments on commit 19d3e28

Please sign in to comment.