From 329fa1c39a61ab39565b7a2e4a31891dd8fad6c9 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 16 Oct 2024 07:19:51 -0400 Subject: [PATCH] set poll in progress from single caller at a time --- core/src/main/java/haveno/core/trade/Trade.java | 14 ++++++++++++-- .../haveno/core/xmr/wallet/XmrWalletService.java | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index 994c6112..dbab49cd 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -2500,10 +2500,18 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { } private void doPollWallet() { + + // skip if shut down started if (isShutDownStarted) return; + + // set poll in progress + boolean pollInProgressSet = false; synchronized (pollLock) { + if (!pollInProgress) pollInProgressSet = true; pollInProgress = true; } + + // poll wallet try { // skip if payout unlocked @@ -2628,8 +2636,10 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { } } } finally { - synchronized (pollLock) { - pollInProgress = false; + if (pollInProgressSet) { + synchronized (pollLock) { + pollInProgress = false; + } } requestSaveWallet(); } diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java index 1a9ead35..6ffd6537 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -1837,10 +1837,18 @@ public class XmrWalletService extends XmrWalletBase { } private void doPollWallet(boolean updateTxs) { + + // skip if shut down started + if (isShutDownStarted) return; + + // set poll in progress + boolean pollInProgressSet = false; synchronized (pollLock) { + if (!pollInProgress) pollInProgressSet = true; pollInProgress = true; } - if (isShutDownStarted) return; + + // poll wallet try { // skip if daemon not synced @@ -1903,8 +1911,10 @@ public class XmrWalletService extends XmrWalletBase { //e.printStackTrace(); } } finally { - synchronized (pollLock) { - pollInProgress = false; + if (pollInProgressSet) { + synchronized (pollLock) { + pollInProgress = false; + } } // cache wallet info last