attempt to recover from stalling the main loop
This commit is contained in:
parent
95df317f56
commit
70e19bc41c
@ -530,7 +530,7 @@ class Blocks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async $updateBlocks() {
|
public async $updateBlocks() {
|
||||||
// warn if this run stalls the main loop for more than 2 minutes
|
// throw an error if this stalls the main loop for more than 2 minutes
|
||||||
const timer = this.startTimer();
|
const timer = this.startTimer();
|
||||||
|
|
||||||
let fastForwarded = false;
|
let fastForwarded = false;
|
||||||
@ -714,6 +714,11 @@ class Blocks {
|
|||||||
|
|
||||||
private updateTimerProgress(state, msg) {
|
private updateTimerProgress(state, msg) {
|
||||||
state.progress = msg;
|
state.progress = msg;
|
||||||
|
if (Date.now() - state.start > this.mainLoopTimeout) {
|
||||||
|
// abort the function if it already timed out
|
||||||
|
logger.err(`$updateBlocks attempted to resume after "${state.progress}"`);
|
||||||
|
throw new Error(`$updateBlocks attempted to resume after "${state.progress}"`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private clearTimer(state) {
|
private clearTimer(state) {
|
||||||
|
@ -122,7 +122,7 @@ class Mempool {
|
|||||||
public async $updateMempool(): Promise<void> {
|
public async $updateMempool(): Promise<void> {
|
||||||
logger.debug(`Updating mempool...`);
|
logger.debug(`Updating mempool...`);
|
||||||
|
|
||||||
// warn if this run stalls the main loop for more than 2 minutes
|
// throw an error if this stalls the main loop for more than 2 minutes
|
||||||
const timer = this.startTimer();
|
const timer = this.startTimer();
|
||||||
|
|
||||||
const start = new Date().getTime();
|
const start = new Date().getTime();
|
||||||
@ -257,6 +257,11 @@ class Mempool {
|
|||||||
|
|
||||||
private updateTimerProgress(state, msg) {
|
private updateTimerProgress(state, msg) {
|
||||||
state.progress = msg;
|
state.progress = msg;
|
||||||
|
if (Date.now() - state.start > this.mainLoopTimeout) {
|
||||||
|
// abort the function if it already timed out
|
||||||
|
logger.err(`$updateMempool attempted to resume after "${state.progress}"`);
|
||||||
|
throw new Error(`$updateMempool attempted to resume after "${state.progress}"`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private clearTimer(state) {
|
private clearTimer(state) {
|
||||||
|
@ -179,8 +179,14 @@ class Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
memPool.deleteExpiredTransactions();
|
memPool.deleteExpiredTransactions();
|
||||||
await blocks.$updateBlocks();
|
await Promise.race([
|
||||||
await memPool.$updateMempool();
|
blocks.$updateBlocks(),
|
||||||
|
new Promise((_, reject) => setTimeout(() => reject(new Error('$updateBlocks timed out')), 180000))
|
||||||
|
]);
|
||||||
|
await Promise.race([
|
||||||
|
memPool.$updateMempool(),
|
||||||
|
new Promise((_, reject) => setTimeout(() => reject(new Error('$updateMempool timed out')), 180000))
|
||||||
|
]);
|
||||||
indexer.$run();
|
indexer.$run();
|
||||||
|
|
||||||
setTimeout(this.runMainUpdateLoop.bind(this), config.MEMPOOL.POLL_RATE_MS);
|
setTimeout(this.runMainUpdateLoop.bind(this), config.MEMPOOL.POLL_RATE_MS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user