Skip to content

Commit 830efcc

Browse files
author
Karl Ranna
committed
fix(raiden): cleanup reconnectTimer on shutdown
This commit fixes a bug where the Raiden reconnect timer would not cleanup when triggering a graceful shutdown. In addition, reconnect timer cleanup has been moved into the `BaseClient`.
1 parent 3411ad6 commit 830efcc

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

lib/BaseClient.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ abstract class BaseClient extends EventEmitter {
4545
public isDisconnected(): boolean {
4646
return this.status === ClientStatus.Disconnected;
4747
}
48+
/** Ends all connections, subscriptions, and timers for for this client. */
49+
public close() {
50+
if (this.reconnectionTimer) {
51+
clearTimeout(this.reconnectionTimer);
52+
}
53+
this.closeSpecific();
54+
}
55+
protected abstract closeSpecific(): void;
4856
}
4957

5058
export default BaseClient;

lib/Xud.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ class Xud extends EventEmitter {
189189
for (const currency in this.lndClients) {
190190
this.lndClients[currency]!.close();
191191
}
192+
if (!this.raidenClient.isDisabled()) {
193+
this.raidenClient.close();
194+
}
192195
// TODO: ensure we are not in the middle of executing any trades
193196
const closePromises: Promise<void>[] = [];
194197

lib/lndclient/LndClient.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,11 @@ class LndClient extends BaseClient {
340340
});
341341
}
342342

343-
/** Ends all subscriptions and reconnection attempts. */
344-
public close = () => {
343+
/** Lnd client specific cleanup. */
344+
protected closeSpecific = () => {
345345
if (this.invoiceSubscription) {
346346
this.invoiceSubscription.cancel();
347347
}
348-
349-
if (this.reconnectionTimer) {
350-
clearTimeout(this.reconnectionTimer);
351-
}
352348
}
353349
}
354350

lib/raidenclient/RaidenClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ class RaidenClient extends BaseClient {
315315
const body = await parseResponseBody<{ our_address: string }>(res);
316316
return body.our_address;
317317
}
318+
319+
/** Raiden client specific cleanup. */
320+
protected closeSpecific() {}
318321
}
319322

320323
export default RaidenClient;

0 commit comments

Comments
 (0)