Gracefully attempt to reconnect to cln upon error

This commit is contained in:
nymkappa
2022-08-04 13:05:15 +02:00
parent faa59f59bd
commit f6d6ea5d31
2 changed files with 16 additions and 5 deletions

View File

@@ -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();
});