mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-16 05:53:06 -04:00
do not open or create wallet after shut down started
This commit is contained in:
parent
6c81347d6c
commit
da49e5fb4a
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user