do not open or create wallet after shut down started

This commit is contained in:
woodser 2025-04-06 20:09:40 -04:00
parent 6c81347d6c
commit da49e5fb4a
No known key found for this signature in database
GPG Key ID: 55A10DD48ADEE5EF
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 Config config;
@Getter
protected boolean isShutdownInProgress;
protected boolean isShutDownStarted;
private boolean isReadOnly;
private Thread keepRunningThread;
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) {
log.info("Starting graceful shut down of {}", getClass().getSimpleName());
// ignore if shut down in progress
if (isShutdownInProgress) {
log.info("Ignoring call to gracefulShutDown, already in progress");
// ignore if shut down started
if (isShutDownStarted) {
log.info("Ignoring call to gracefulShutDown, already started");
return;
}
isShutdownInProgress = true;
isShutDownStarted = true;
ResultHandler resultHandler;
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
Set<Runnable> tasks = new HashSet<Runnable>();
tasks.add(() -> injector.getInstance(TradeManager.class).onShutDownStarted());
tasks.add(() -> injector.getInstance(XmrWalletService.class).onShutDownStarted());
tasks.add(() -> injector.getInstance(XmrConnectionService.class).onShutDownStarted());
tasks.add(() -> injector.getInstance(TradeManager.class).onShutDownStarted());
try {
ThreadUtils.awaitTasks(tasks, tasks.size(), 90000l); // run in parallel with timeout
} catch (Exception e) {

View File

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

View File

@ -1659,6 +1659,7 @@ public class XmrWalletService extends XmrWalletBase {
walletRpc.stopSyncing();
// create wallet
if (isShutDownStarted) throw new IllegalStateException("Cannot create wallet '" + config.getPath() + "' because shutdown is started");
MoneroRpcConnection connection = xmrConnectionService.getConnection();
log.info("Creating RPC wallet " + config.getPath() + " connected to monerod=" + connection.getUri());
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");
return walletRpc;
} catch (Exception e) {
log.warn("Could not create wallet '" + config.getPath() + "': " + e.getMessage() + "\n", e);
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);
// 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());
config.setServer(connection);
try {
@ -1764,7 +1765,6 @@ public class XmrWalletService extends XmrWalletBase {
log.info("Done opening RPC wallet " + config.getPath());
return walletRpc;
} catch (Exception e) {
log.warn("Could not open wallet '" + config.getPath() + "': " + e.getMessage() + "\n", e);
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());
}

View File

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