Merge pull request #2251 from mempool/nymkappa/bugfix/clightning-crash
Don't throw an exception when cln connection is down
This commit is contained in:
		
						commit
						c0e6b7af58
					
				@ -157,8 +157,18 @@ export default class CLightningClient extends EventEmitter implements AbstractLi
 | 
			
		||||
 | 
			
		||||
    const _self = this;
 | 
			
		||||
 | 
			
		||||
    this.client = createConnection(rpcPath);
 | 
			
		||||
    this.rl = createInterface({ input: this.client })
 | 
			
		||||
    this.client = createConnection(rpcPath).on(
 | 
			
		||||
      'error', () => {
 | 
			
		||||
        _self.increaseWaitTime();
 | 
			
		||||
        _self.reconnect();
 | 
			
		||||
      }
 | 
			
		||||
    );
 | 
			
		||||
    this.rl = createInterface({ input: this.client }).on(
 | 
			
		||||
      'error', () => {
 | 
			
		||||
        _self.increaseWaitTime();
 | 
			
		||||
        _self.reconnect();
 | 
			
		||||
      }
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    this.clientConnectionPromise = new Promise<void>(resolve => {
 | 
			
		||||
      _self.client.on('connect', () => {
 | 
			
		||||
@ -175,7 +185,6 @@ export default class CLightningClient extends EventEmitter implements AbstractLi
 | 
			
		||||
 | 
			
		||||
      _self.client.on('error', error => {
 | 
			
		||||
        logger.err(`[CLightningClient] Lightning client connection error: ${error}`);
 | 
			
		||||
        _self.emit('error', error);
 | 
			
		||||
        _self.increaseWaitTime();
 | 
			
		||||
        _self.reconnect();
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ import { ILightningApi } from '../../api/lightning/lightning-api.interface';
 | 
			
		||||
import { $lookupNodeLocation } from './sync-tasks/node-locations';
 | 
			
		||||
import lightningApi from '../../api/lightning/lightning-api-factory';
 | 
			
		||||
import { convertChannelId } from '../../api/lightning/clightning/clightning-convert';
 | 
			
		||||
import { Common } from '../../api/common';
 | 
			
		||||
 | 
			
		||||
class NetworkSyncService {
 | 
			
		||||
  constructor() {}
 | 
			
		||||
@ -23,14 +24,15 @@ class NetworkSyncService {
 | 
			
		||||
    }, 1000 * 60 * 60);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private async $runUpdater() {
 | 
			
		||||
  private async $runUpdater(): Promise<void> {
 | 
			
		||||
    try {
 | 
			
		||||
      logger.info(`Updating nodes and channels...`);
 | 
			
		||||
 | 
			
		||||
      const networkGraph = await lightningApi.$getNetworkGraph();
 | 
			
		||||
      if (networkGraph.nodes.length === 0 || networkGraph.edges.length === 0) {
 | 
			
		||||
        logger.info(`LN Network graph is empty, retrying in 10 seconds`);
 | 
			
		||||
        setTimeout(this.$runUpdater, 10000);
 | 
			
		||||
        await Common.sleep$(10000);
 | 
			
		||||
        this.$runUpdater();
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user