diff --git a/backend/src/index.ts b/backend/src/index.ts index 976ec12df..683f964f0 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -137,9 +137,7 @@ class Server { } if (config.LIGHTNING.ENABLED) { - fundingTxFetcher.$init() - .then(() => networkSyncService.$startService()) - .then(() => lightningStatsUpdater.$startService()); + this.$runLightningBackend(); } this.server.listen(config.MEMPOOL.HTTP_PORT, () => { @@ -185,6 +183,18 @@ class Server { } } + async $runLightningBackend() { + try { + await fundingTxFetcher.$init(); + await networkSyncService.$startService(); + await lightningStatsUpdater.$startService(); + } catch(e) { + logger.err(`Lightning backend crashed. Restarting in 1 minute. Reason: ${(e instanceof Error ? e.message : e)}`); + await Common.sleep$(1000 * 60); + this.$runLightningBackend(); + }; +} + setUpWebsocketHandling() { if (this.wss) { websocketHandler.setWebsocketServer(this.wss);