do not open or create wallet after shut down started

This commit is contained in:
woodser 2025-04-06 20:09:40 -04:00 committed by woodser
parent 9027ce6634
commit 08b0b36436
4 changed files with 22 additions and 22 deletions

View file

@ -100,7 +100,7 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven
protected AppModule module; protected AppModule module;
protected Config config; protected Config config;
@Getter @Getter
protected boolean isShutdownInProgress; protected boolean isShutDownStarted;
private boolean isReadOnly; private boolean isReadOnly;
private Thread keepRunningThread; private Thread keepRunningThread;
private AtomicInteger keepRunningResult = new AtomicInteger(EXIT_SUCCESS); private AtomicInteger keepRunningResult = new AtomicInteger(EXIT_SUCCESS);
@ -330,12 +330,12 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven
public void gracefulShutDown(ResultHandler onShutdown, boolean systemExit) { public void gracefulShutDown(ResultHandler onShutdown, boolean systemExit) {
log.info("Starting graceful shut down of {}", getClass().getSimpleName()); log.info("Starting graceful shut down of {}", getClass().getSimpleName());
// ignore if shut down in progress // ignore if shut down started
if (isShutdownInProgress) { if (isShutDownStarted) {
log.info("Ignoring call to gracefulShutDown, already in progress"); log.info("Ignoring call to gracefulShutDown, already started");
return; return;
} }
isShutdownInProgress = true; isShutDownStarted = true;
ResultHandler resultHandler; ResultHandler resultHandler;
if (shutdownCompletedHandler != null) { if (shutdownCompletedHandler != null) {
@ -357,9 +357,9 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven
// notify trade protocols and wallets to prepare for shut down before shutting down // notify trade protocols and wallets to prepare for shut down before shutting down
Set<Runnable> tasks = new HashSet<Runnable>(); Set<Runnable> tasks = new HashSet<Runnable>();
tasks.add(() -> injector.getInstance(TradeManager.class).onShutDownStarted());
tasks.add(() -> injector.getInstance(XmrWalletService.class).onShutDownStarted()); tasks.add(() -> injector.getInstance(XmrWalletService.class).onShutDownStarted());
tasks.add(() -> injector.getInstance(XmrConnectionService.class).onShutDownStarted()); tasks.add(() -> injector.getInstance(XmrConnectionService.class).onShutDownStarted());
tasks.add(() -> injector.getInstance(TradeManager.class).onShutDownStarted());
try { try {
ThreadUtils.awaitTasks(tasks, tasks.size(), 90000l); // run in parallel with timeout ThreadUtils.awaitTasks(tasks, tasks.size(), 90000l); // run in parallel with timeout
} catch (Exception e) { } catch (Exception e) {

View file

@ -105,21 +105,21 @@ public abstract class ExecutableForAppWithP2p extends HavenoExecutable {
public void gracefulShutDown(ResultHandler resultHandler) { public void gracefulShutDown(ResultHandler resultHandler) {
log.info("Starting graceful shut down of {}", getClass().getSimpleName()); log.info("Starting graceful shut down of {}", getClass().getSimpleName());
// ignore if shut down in progress // ignore if shut down started
if (isShutdownInProgress) { if (isShutDownStarted) {
log.info("Ignoring call to gracefulShutDown, already in progress"); log.info("Ignoring call to gracefulShutDown, already started");
return; return;
} }
isShutdownInProgress = true; isShutDownStarted = true;
try { try {
if (injector != null) { if (injector != null) {
// notify trade protocols and wallets to prepare for shut down // notify trade protocols and wallets to prepare for shut down
Set<Runnable> tasks = new HashSet<Runnable>(); Set<Runnable> tasks = new HashSet<Runnable>();
tasks.add(() -> injector.getInstance(TradeManager.class).onShutDownStarted());
tasks.add(() -> injector.getInstance(XmrWalletService.class).onShutDownStarted()); tasks.add(() -> injector.getInstance(XmrWalletService.class).onShutDownStarted());
tasks.add(() -> injector.getInstance(XmrConnectionService.class).onShutDownStarted()); tasks.add(() -> injector.getInstance(XmrConnectionService.class).onShutDownStarted());
tasks.add(() -> injector.getInstance(TradeManager.class).onShutDownStarted());
try { try {
ThreadUtils.awaitTasks(tasks, tasks.size(), 120000l); // run in parallel with timeout ThreadUtils.awaitTasks(tasks, tasks.size(), 120000l); // run in parallel with timeout
} catch (Exception e) { } catch (Exception e) {

View file

@ -1659,6 +1659,7 @@ public class XmrWalletService extends XmrWalletBase {
walletRpc.stopSyncing(); walletRpc.stopSyncing();
// create wallet // create wallet
if (isShutDownStarted) throw new IllegalStateException("Cannot create wallet '" + config.getPath() + "' because shutdown is started");
MoneroRpcConnection connection = xmrConnectionService.getConnection(); MoneroRpcConnection connection = xmrConnectionService.getConnection();
log.info("Creating RPC wallet " + config.getPath() + " connected to monerod=" + connection.getUri()); log.info("Creating RPC wallet " + config.getPath() + " connected to monerod=" + connection.getUri());
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
@ -1668,9 +1669,8 @@ public class XmrWalletService extends XmrWalletBase {
log.info("Done creating RPC wallet " + config.getPath() + " in " + (System.currentTimeMillis() - time) + " ms"); log.info("Done creating RPC wallet " + config.getPath() + " in " + (System.currentTimeMillis() - time) + " ms");
return walletRpc; return walletRpc;
} catch (Exception e) { } catch (Exception e) {
log.warn("Could not create wallet '" + config.getPath() + "': " + e.getMessage() + "\n", e);
if (walletRpc != null) forceCloseWallet(walletRpc, config.getPath()); if (walletRpc != null) forceCloseWallet(walletRpc, config.getPath());
throw new IllegalStateException("Could not create wallet '" + config.getPath() + "'. Please close Haveno, stop all monero-wallet-rpc processes in your task manager, and restart Haveno."); throw new IllegalStateException("Could not create wallet '" + config.getPath() + "'. Please close Haveno, stop all monero-wallet-rpc processes in your task manager, and restart Haveno.\n\nError message: " + e.getMessage());
} }
} }
@ -1690,6 +1690,7 @@ public class XmrWalletService extends XmrWalletBase {
if (!applyProxyUri) connection.setProxyUri(null); if (!applyProxyUri) connection.setProxyUri(null);
// try opening wallet // try opening wallet
if (isShutDownStarted) throw new IllegalStateException("Cannot open wallet '" + config.getPath() + "' because shutdown is started");
log.info("Opening RPC wallet '{}' with monerod={}, proxyUri={}", config.getPath(), connection.getUri(), connection.getProxyUri()); log.info("Opening RPC wallet '{}' with monerod={}, proxyUri={}", config.getPath(), connection.getUri(), connection.getProxyUri());
config.setServer(connection); config.setServer(connection);
try { try {
@ -1764,7 +1765,6 @@ public class XmrWalletService extends XmrWalletBase {
log.info("Done opening RPC wallet " + config.getPath()); log.info("Done opening RPC wallet " + config.getPath());
return walletRpc; return walletRpc;
} catch (Exception e) { } catch (Exception e) {
log.warn("Could not open wallet '" + config.getPath() + "': " + e.getMessage() + "\n", e);
if (walletRpc != null) forceCloseWallet(walletRpc, config.getPath()); if (walletRpc != null) forceCloseWallet(walletRpc, config.getPath());
throw new IllegalStateException("Could not open wallet '" + config.getPath() + "'. Please close Haveno, stop all monero-wallet-rpc processes in your task manager, and restart Haveno.\n\nError message: " + e.getMessage()); throw new IllegalStateException("Could not open wallet '" + config.getPath() + "'. Please close Haveno, stop all monero-wallet-rpc processes in your task manager, and restart Haveno.\n\nError message: " + e.getMessage());
} }

View file

@ -40,8 +40,8 @@ public class TorNetworkNodeNetlayer extends TorNetworkNode {
private Tor tor; private Tor tor;
private final String torControlHost; private final String torControlHost;
private Timer shutDownTimeoutTimer; private Timer shutDownTimeoutTimer;
private boolean shutDownInProgress; private boolean isShutDownStarted;
private boolean shutDownComplete; private boolean isShutDownComplete;
public TorNetworkNodeNetlayer(int servicePort, public TorNetworkNodeNetlayer(int servicePort,
NetworkProtoResolver networkProtoResolver, NetworkProtoResolver networkProtoResolver,
@ -65,20 +65,20 @@ public class TorNetworkNodeNetlayer extends TorNetworkNode {
@Override @Override
public void shutDown(@Nullable Runnable shutDownCompleteHandler) { public void shutDown(@Nullable Runnable shutDownCompleteHandler) {
log.info("TorNetworkNodeNetlayer shutdown started"); log.info("TorNetworkNodeNetlayer shutdown started");
if (shutDownComplete) { if (isShutDownComplete) {
log.info("TorNetworkNodeNetlayer shutdown already completed"); log.info("TorNetworkNodeNetlayer shutdown already completed");
if (shutDownCompleteHandler != null) shutDownCompleteHandler.run(); if (shutDownCompleteHandler != null) shutDownCompleteHandler.run();
return; return;
} }
if (shutDownInProgress) { if (isShutDownStarted) {
log.warn("Ignoring request to shut down because shut down is in progress"); log.warn("Ignoring request to shut down because shut down already started");
return; return;
} }
shutDownInProgress = true; isShutDownStarted = true;
shutDownTimeoutTimer = UserThread.runAfter(() -> { shutDownTimeoutTimer = UserThread.runAfter(() -> {
log.error("A timeout occurred at shutDown"); log.error("A timeout occurred at shutDown");
shutDownComplete = true; isShutDownComplete = true;
if (shutDownCompleteHandler != null) shutDownCompleteHandler.run(); if (shutDownCompleteHandler != null) shutDownCompleteHandler.run();
executor.shutdownNow(); executor.shutdownNow();
}, SHUT_DOWN_TIMEOUT); }, SHUT_DOWN_TIMEOUT);
@ -96,7 +96,7 @@ public class TorNetworkNodeNetlayer extends TorNetworkNode {
log.error("Shutdown TorNetworkNodeNetlayer failed with exception", e); log.error("Shutdown TorNetworkNodeNetlayer failed with exception", e);
} finally { } finally {
shutDownTimeoutTimer.stop(); shutDownTimeoutTimer.stop();
shutDownComplete = true; isShutDownComplete = true;
if (shutDownCompleteHandler != null) shutDownCompleteHandler.run(); if (shutDownCompleteHandler != null) shutDownCompleteHandler.run();
} }
}); });