shut down trades before main wallet to finish processing

This commit is contained in:
woodser 2023-12-17 06:51:51 -05:00
parent de3317b05d
commit 30e199c56e
3 changed files with 31 additions and 18 deletions

View File

@ -346,6 +346,7 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven
e.printStackTrace(); e.printStackTrace();
} }
injector.getInstance(TradeManager.class).shutDown();
injector.getInstance(PriceFeedService.class).shutDown(); injector.getInstance(PriceFeedService.class).shutDown();
injector.getInstance(ArbitratorManager.class).shutDown(); injector.getInstance(ArbitratorManager.class).shutDown();
injector.getInstance(TradeStatisticsManager.class).shutDown(); injector.getInstance(TradeStatisticsManager.class).shutDown();
@ -362,10 +363,12 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven
injector.getInstance(P2PService.class).shutDown(() -> { injector.getInstance(P2PService.class).shutDown(() -> {
log.info("Done shutting down OpenOfferManager, OfferBookService, and P2PService"); log.info("Done shutting down OpenOfferManager, OfferBookService, and P2PService");
// shut down connections pool
log.info("Shutting down connections");
Connection.shutDownExecutor(30);
// shut down monero wallets and connections // shut down monero wallets and connections
injector.getInstance(WalletsSetup.class).shutDownComplete.addListener((ov, o, n) -> { injector.getInstance(WalletsSetup.class).shutDownComplete.addListener((ov, o, n) -> {
log.info("Shutting down connections");
Connection.shutDownExecutor(30);
// done shutting down // done shutting down
log.info("Graceful shutdown completed. Exiting now."); log.info("Graceful shutdown completed. Exiting now.");

View File

@ -27,12 +27,15 @@ import haveno.common.persistence.PersistenceManager;
import haveno.common.setup.GracefulShutDownHandler; import haveno.common.setup.GracefulShutDownHandler;
import haveno.common.util.Profiler; import haveno.common.util.Profiler;
import haveno.core.api.XmrConnectionService; import haveno.core.api.XmrConnectionService;
import haveno.core.app.AvoidStandbyModeService;
import haveno.core.app.HavenoExecutable; import haveno.core.app.HavenoExecutable;
import haveno.core.offer.OfferBookService; import haveno.core.offer.OfferBookService;
import haveno.core.offer.OpenOfferManager; import haveno.core.offer.OpenOfferManager;
import haveno.core.provider.price.PriceFeedService;
import haveno.core.support.dispute.arbitration.arbitrator.ArbitratorManager; import haveno.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
import haveno.core.trade.HavenoUtils; import haveno.core.trade.HavenoUtils;
import haveno.core.trade.TradeManager; import haveno.core.trade.TradeManager;
import haveno.core.trade.statistics.TradeStatisticsManager;
import haveno.core.xmr.setup.WalletsSetup; import haveno.core.xmr.setup.WalletsSetup;
import haveno.core.xmr.wallet.BtcWalletService; import haveno.core.xmr.wallet.BtcWalletService;
import haveno.core.xmr.wallet.XmrWalletService; import haveno.core.xmr.wallet.XmrWalletService;
@ -107,7 +110,11 @@ public abstract class ExecutableForAppWithP2p extends HavenoExecutable {
} }
JsonFileManager.shutDownAllInstances(); JsonFileManager.shutDownAllInstances();
injector.getInstance(TradeManager.class).shutDown();
injector.getInstance(PriceFeedService.class).shutDown();
injector.getInstance(ArbitratorManager.class).shutDown(); injector.getInstance(ArbitratorManager.class).shutDown();
injector.getInstance(TradeStatisticsManager.class).shutDown();
injector.getInstance(AvoidStandbyModeService.class).shutDown();
// shut down open offer manager // shut down open offer manager
log.info("Shutting down OpenOfferManager, OfferBookService, and P2PService"); log.info("Shutting down OpenOfferManager, OfferBookService, and P2PService");
@ -120,12 +127,14 @@ public abstract class ExecutableForAppWithP2p extends HavenoExecutable {
injector.getInstance(P2PService.class).shutDown(() -> { injector.getInstance(P2PService.class).shutDown(() -> {
log.info("Done shutting down OpenOfferManager, OfferBookService, and P2PService"); log.info("Done shutting down OpenOfferManager, OfferBookService, and P2PService");
// shut down connections pool
log.info("Shutting down connections");
Connection.shutDownExecutor(30);
// shut down monero wallets and connections // shut down monero wallets and connections
injector.getInstance(WalletsSetup.class).shutDownComplete.addListener((ov, o, n) -> { injector.getInstance(WalletsSetup.class).shutDownComplete.addListener((ov, o, n) -> {
module.close(injector); module.close(injector);
PersistenceManager.flushAllDataToDiskAtShutdown(() -> { PersistenceManager.flushAllDataToDiskAtShutdown(() -> {
log.info("Shutting down connections");
Connection.shutDownExecutor(30);
// done shutting down // done shutting down
log.info("Graceful shutdown completed. Exiting now."); log.info("Graceful shutdown completed. Exiting now.");

View File

@ -664,9 +664,11 @@ public class XmrWalletService {
// remove listeners which stops polling wallet // remove listeners which stops polling wallet
// TODO monero-java: wallet.stopPolling()? // TODO monero-java: wallet.stopPolling()?
if (wallet != null) { synchronized (walletLock) {
for (MoneroWalletListenerI listener : new HashSet<>(wallet.getListeners())) { if (wallet != null) {
wallet.removeListener(listener); for (MoneroWalletListenerI listener : new HashSet<>(wallet.getListeners())) {
wallet.removeListener(listener);
}
} }
} }
} }
@ -676,10 +678,7 @@ public class XmrWalletService {
// shut down trade and main wallets at same time // shut down trade and main wallets at same time
walletListeners.clear(); walletListeners.clear();
List<Runnable> tasks = new ArrayList<Runnable>(); closeMainWallet(true);
if (tradeManager != null) tasks.add(() -> tradeManager.shutDown());
tasks.add(() -> closeMainWallet(true));
HavenoUtils.awaitTasks(tasks);
log.info("Done shutting down all wallets"); log.info("Done shutting down all wallets");
} }
@ -984,13 +983,15 @@ public class XmrWalletService {
} }
private void closeMainWallet(boolean save) { private void closeMainWallet(boolean save) {
try { synchronized (walletLock) {
if (wallet != null) { try {
closeWallet(wallet, true); if (wallet != null) {
wallet = null; closeWallet(wallet, true);
wallet = null;
}
} catch (Exception e) {
log.warn("Error closing main monero-wallet-rpc subprocess: " + e.getMessage() + ". Was Haveno stopped manually with ctrl+c?");
} }
} catch (Exception e) {
log.warn("Error closing main monero-wallet-rpc subprocess: " + e.getMessage() + ". Was Haveno stopped manually with ctrl+c?");
} }
} }