mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-10 15:40:22 -04:00
repeatedly acquire lock on trade shut down and fix timeout
This commit is contained in:
parent
5cc53a82e3
commit
db155283be
6 changed files with 56 additions and 36 deletions
|
@ -341,7 +341,7 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven
|
|||
tasks.add(() -> injector.getInstance(XmrConnectionService.class).onShutDownStarted());
|
||||
tasks.add(() -> injector.getInstance(TradeManager.class).onShutDownStarted());
|
||||
try {
|
||||
ThreadUtils.awaitTasks(tasks, tasks.size(), 120l); // run in parallel with timeout
|
||||
ThreadUtils.awaitTasks(tasks, tasks.size(), 120000l); // run in parallel with timeout
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ public abstract class ExecutableForAppWithP2p extends HavenoExecutable {
|
|||
tasks.add(() -> injector.getInstance(XmrConnectionService.class).onShutDownStarted());
|
||||
tasks.add(() -> injector.getInstance(TradeManager.class).onShutDownStarted());
|
||||
try {
|
||||
ThreadUtils.awaitTasks(tasks, tasks.size(), 120l); // run in parallel with timeout
|
||||
ThreadUtils.awaitTasks(tasks, tasks.size(), 120000l); // run in parallel with timeout
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1226,14 +1226,31 @@ public abstract class Trade implements Tradable, Model {
|
|||
isShutDownStarted = true;
|
||||
if (!isPayoutUnlocked()) log.info("Shutting down {} {}", getClass().getSimpleName(), getId());
|
||||
|
||||
// shut down thread pools with timeout
|
||||
List<Runnable> tasks = new ArrayList<>();
|
||||
tasks.add(() -> ThreadUtils.shutDown(getId(), SHUTDOWN_TIMEOUT_MS));
|
||||
tasks.add(() -> ThreadUtils.shutDown(getConnectionChangedThreadId(), SHUTDOWN_TIMEOUT_MS));
|
||||
// create task to shut down trade
|
||||
Runnable shutDownTask = () -> {
|
||||
|
||||
// repeatedly acquire lock to clear tasks
|
||||
for (int i = 0; i < 20; i++) {
|
||||
synchronized (this) {
|
||||
GenUtils.waitFor(10);
|
||||
}
|
||||
}
|
||||
|
||||
// shut down trade threads
|
||||
synchronized (this) {
|
||||
List<Runnable> shutDownThreads = new ArrayList<>();
|
||||
shutDownThreads.add(() -> ThreadUtils.shutDown(getId()));
|
||||
shutDownThreads.add(() -> ThreadUtils.shutDown(getConnectionChangedThreadId()));
|
||||
ThreadUtils.awaitTasks(shutDownThreads);
|
||||
}
|
||||
};
|
||||
|
||||
// shut down trade with timeout
|
||||
try {
|
||||
ThreadUtils.awaitTasks(tasks);
|
||||
ThreadUtils.awaitTask(shutDownTask, SHUTDOWN_TIMEOUT_MS);
|
||||
} catch (Exception e) {
|
||||
log.warn("Timeout shutting down {} {}", getClass().getSimpleName(), getId());
|
||||
log.warn("Error shutting down {} {}: {}", getClass().getSimpleName(), getId(), e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
||||
// force stop wallet
|
||||
if (wallet != null) {
|
||||
|
@ -1251,8 +1268,13 @@ public abstract class Trade implements Tradable, Model {
|
|||
idlePayoutSyncer = null;
|
||||
}
|
||||
if (wallet != null) {
|
||||
xmrWalletService.saveWallet(wallet, false); // skip backup
|
||||
stopWallet();
|
||||
try {
|
||||
xmrWalletService.saveWallet(wallet, false); // skip backup
|
||||
stopWallet();
|
||||
} catch (Exception e) {
|
||||
// warning will be logged for main wallet, so skip logging here
|
||||
//log.warn("Error closing monero-wallet-rpc subprocess for {} {}: {}. Was Haveno stopped manually with ctrl+c?", getClass().getSimpleName(), getId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
UserThread.execute(() -> {
|
||||
if (tradeStateSubscription != null) tradeStateSubscription.unsubscribe();
|
||||
|
|
|
@ -952,6 +952,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
|||
}
|
||||
|
||||
private void updateTradePeriodState() {
|
||||
if (isShutDownStarted) return;
|
||||
for (Trade trade : new ArrayList<Trade>(tradableList.getList())) {
|
||||
if (!trade.isPayoutPublished()) {
|
||||
Date maxTradePeriodDate = trade.getMaxTradePeriodDate();
|
||||
|
|
|
@ -1047,7 +1047,7 @@ public class XmrWalletService {
|
|||
wallet = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Error closing main monero-wallet-rpc subprocess: " + e.getMessage() + ". Was Haveno stopped manually with ctrl+c?");
|
||||
log.warn("Error closing main monero-wallet-rpc subprocess: {}. Was Haveno stopped manually with ctrl+c?", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue