Skip to content

Commit 86d2b20

Browse files
sangamanmichael1011
authored andcommitted
fix(lnd): waitForReady infinite deadline (#1152)
This fixes a bug where the first attempt to verify a connection to lnd would fail on the first attempt due to the `deadline` of 0 for the `waitForReady` being exceeded immediately with the latest version of lnd. Subsequent attempts would not exceed the deadline. Instead, this always uses a deadline of infinity meaning xud will always wait for lnd to be online before it attempts a `GetInfo` call to verify the connection. This leverages the recently added `verifyConnectionWithTimeout` logic to timeout the initial connection verification if lnd remains offline so that it doesn't hold up the xud initialization procedure.
1 parent 7737da8 commit 86d2b20

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/lndclient/LndClient.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,10 @@ class LndClient extends SwapClient {
237237
}
238238

239239
if (!this.isConnected()) {
240-
this.logger.debug(`trying to verify connection to lnd at ${this.uri}`);
240+
this.logger.info(`trying to verify connection to lnd at ${this.uri}`);
241241
const lightningClient = new LightningClient(this.uri, this.credentials);
242242
const clientReadyPromise = new Promise((resolve, reject) => {
243-
// if we're not initialized, don't wait for lnd to come online and mark client as disconnected immediately
244-
const deadline = this.isNotInitialized() ? 0 : Number.POSITIVE_INFINITY;
245-
lightningClient.waitForReady(deadline, (err) => {
243+
lightningClient.waitForReady(Number.POSITIVE_INFINITY, (err) => {
246244
if (err) {
247245
reject(err);
248246
} else {
@@ -310,8 +308,8 @@ class LndClient extends SwapClient {
310308
this.lightning = undefined;
311309
await this.setStatus(ClientStatus.WaitingUnlock);
312310
} else {
313-
this.logger.error(`could not verify connection to lnd at ${this.uri}, error: ${JSON.stringify(err)},
314-
retrying in ${LndClient.RECONNECT_TIMER} ms`);
311+
const errStr = typeof(err) === 'string' ? err : JSON.stringify(err);
312+
this.logger.error(`could not verify connection at ${this.uri}, error: ${errStr}, retrying in ${LndClient.RECONNECT_TIMER} ms`);
315313
await this.disconnect();
316314
}
317315
}

lib/swaps/SwapClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ abstract class SwapClient extends EventEmitter {
7878
return new Promise<void>((resolve, reject) => {
7979
const verifyTimeout = setTimeout(() => {
8080
// we could not verify the connection within the allotted time
81+
this.logger.info(`could not verify connection within initialization time limit of ${SwapClient.INITIALIZATION_TIME_LIMIT}`);
8182
resolve();
8283
}, SwapClient.INITIALIZATION_TIME_LIMIT);
8384
this.verifyConnection().then(() => {

0 commit comments

Comments
 (0)