mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-23 04:29:22 +00:00
force restart trade wallet on connection refused during poll
This commit is contained in:
parent
2a2eb0c82f
commit
eb323f6d65
2 changed files with 30 additions and 11 deletions
|
@ -125,6 +125,7 @@ public abstract class Trade implements Tradable, Model {
|
||||||
private MoneroWallet wallet;
|
private MoneroWallet wallet;
|
||||||
boolean wasWalletSynced;
|
boolean wasWalletSynced;
|
||||||
boolean pollInProgress;
|
boolean pollInProgress;
|
||||||
|
boolean restartInProgress;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Enums
|
// Enums
|
||||||
|
@ -898,6 +899,14 @@ public abstract class Trade implements Tradable, Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void forceStopWallet() {
|
||||||
|
if (wallet != null) {
|
||||||
|
log.warn("Force stopping wallet for {} {}", getClass().getSimpleName(), getId());
|
||||||
|
xmrWalletService.stopWallet(wallet, wallet.getPath(), true);
|
||||||
|
wallet = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteWallet() {
|
public void deleteWallet() {
|
||||||
synchronized (walletLock) {
|
synchronized (walletLock) {
|
||||||
if (walletExists()) {
|
if (walletExists()) {
|
||||||
|
@ -1321,11 +1330,7 @@ public abstract class Trade implements Tradable, Model {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
// force stop wallet
|
// force stop wallet
|
||||||
if (wallet != null) {
|
forceStopWallet();
|
||||||
log.warn("Force stopping wallet for {} {}", getClass().getSimpleName(), getId());
|
|
||||||
xmrWalletService.stopWallet(wallet, wallet.getPath(), true);
|
|
||||||
wallet = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// de-initialize
|
// de-initialize
|
||||||
|
@ -2151,11 +2156,15 @@ public abstract class Trade implements Tradable, Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
boolean isWalletConnected = isWalletConnectedToDaemon();
|
boolean isConnectionRefused = e.getMessage() != null && e.getMessage().contains("Connection refused");
|
||||||
if (!isWalletConnected) xmrConnectionService.checkConnection(); // check connection if wallet is not connected
|
if (isConnectionRefused) forceRestartTradeWallet();
|
||||||
if (!isShutDownStarted && wallet != null && isWalletConnected) {
|
else {
|
||||||
log.warn("Error polling trade wallet for {} {}: {}. Monerod={}", getClass().getSimpleName(), getId(), e.getMessage(), getXmrWalletService().getConnectionService().getConnection());
|
boolean isWalletConnected = isWalletConnectedToDaemon();
|
||||||
//e.printStackTrace();
|
if (!isWalletConnected) xmrConnectionService.checkConnection(); // check connection if wallet is not connected
|
||||||
|
if (!isShutDownStarted && wallet != null && isWalletConnected) {
|
||||||
|
log.warn("Error polling trade wallet for {} {}: {}. Monerod={}", getClass().getSimpleName(), getId(), e.getMessage(), getXmrWalletService().getConnectionService().getConnection());
|
||||||
|
//e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
pollInProgress = false;
|
pollInProgress = false;
|
||||||
|
@ -2163,6 +2172,16 @@ public abstract class Trade implements Tradable, Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void forceRestartTradeWallet() {
|
||||||
|
log.warn("Force restarting trade wallet for {} {}", getClass().getSimpleName(), getId());
|
||||||
|
if (isShutDownStarted || restartInProgress) return;
|
||||||
|
restartInProgress = true;
|
||||||
|
forceStopWallet();
|
||||||
|
if (!isShutDownStarted) wallet = getWallet();
|
||||||
|
restartInProgress = false;
|
||||||
|
if (!isShutDownStarted) ThreadUtils.execute(() -> tryInitSyncing(), getId());
|
||||||
|
}
|
||||||
|
|
||||||
private long getWalletRefreshPeriod() {
|
private long getWalletRefreshPeriod() {
|
||||||
if (isIdling()) return IDLE_SYNC_PERIOD_MS;
|
if (isIdling()) return IDLE_SYNC_PERIOD_MS;
|
||||||
return xmrConnectionService.getRefreshPeriodMs();
|
return xmrConnectionService.getRefreshPeriodMs();
|
||||||
|
|
|
@ -754,7 +754,7 @@ public class XmrWalletService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shut down trade and main wallets at same time
|
// shut down main wallet
|
||||||
walletListeners.clear();
|
walletListeners.clear();
|
||||||
closeMainWallet(true);
|
closeMainWallet(true);
|
||||||
log.info("Done shutting down main wallet");
|
log.info("Done shutting down main wallet");
|
||||||
|
|
Loading…
Reference in a new issue