Skip to content

Commit

Permalink
fix(raiden): cleanup reconnectTimer on shutdown
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Karl Ranna committed Mar 23, 2019
1 parent 3411ad6 commit 830efcc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
8 changes: 8 additions & 0 deletions lib/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ abstract class BaseClient extends EventEmitter {
public isDisconnected(): boolean {
return this.status === ClientStatus.Disconnected;
}
/** Ends all connections, subscriptions, and timers for for this client. */
public close() {
if (this.reconnectionTimer) {
clearTimeout(this.reconnectionTimer);
}
this.closeSpecific();
}
protected abstract closeSpecific(): void;
}

export default BaseClient;
Expand Down
3 changes: 3 additions & 0 deletions lib/Xud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class Xud extends EventEmitter {
for (const currency in this.lndClients) {
this.lndClients[currency]!.close();
}
if (!this.raidenClient.isDisabled()) {
this.raidenClient.close();
}
// TODO: ensure we are not in the middle of executing any trades
const closePromises: Promise<void>[] = [];

Expand Down
8 changes: 2 additions & 6 deletions lib/lndclient/LndClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,11 @@ class LndClient extends BaseClient {
});
}

/** Ends all subscriptions and reconnection attempts. */
public close = () => {
/** Lnd client specific cleanup. */
protected closeSpecific = () => {
if (this.invoiceSubscription) {
this.invoiceSubscription.cancel();
}

if (this.reconnectionTimer) {
clearTimeout(this.reconnectionTimer);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/raidenclient/RaidenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ class RaidenClient extends BaseClient {
const body = await parseResponseBody<{ our_address: string }>(res);
return body.our_address;
}

/** Raiden client specific cleanup. */
protected closeSpecific() {}
}

export default RaidenClient;
Expand Down

0 comments on commit 830efcc

Please sign in to comment.