From f4974156d96dc3f821ca59bcb8d4aab2db4a3f65 Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Thu, 9 Apr 2020 03:11:34 -0400 Subject: [PATCH] fix(lnd): relax unhandled openchannel timeout This removes the hard timeout placed on each attempt to connect to a peer's lnd node when attempting to open a channel with that peer. This timeout was causing xud to crash because it threw an error that was not being handled in the encapsulating catch block, which did not catch the error because it was thrown from a callback. Rather than attempt to correct the asynchronous exception handling, this lifts the timeout limit set within xud and instead will wait on each connect attempt until it succeeds, times out, or fails according to the logic within lnd. Fixes #1405. --- lib/lndclient/LndClient.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/lndclient/LndClient.ts b/lib/lndclient/LndClient.ts index 166876e34..8b956a4ab 100644 --- a/lib/lndclient/LndClient.ts +++ b/lib/lndclient/LndClient.ts @@ -725,14 +725,13 @@ class LndClient extends SwapClient { if (connectionEstablished) { await this.openChannelSync(peerPubKey, units); } else { - throw new Error('connectPeerAddreses failed'); + throw new Error('could not connect to lnd uris for ${peerPubKey}'); } } /** - * Tries to connect to a given list of peer's node addresses - * in a sequential order. - * Returns true when successful, otherwise false. + * Tries to connect to a given list of a peer's uris in sequential order. + * @returns `true` when successful, otherwise `false`. */ private connectPeerAddreses = async ( peerListeningUris: string[], @@ -745,23 +744,16 @@ class LndClient extends SwapClient { address: splitUri[1], }; }); - const CONNECT_TIMEOUT = 4000; for (const uri of splitListeningUris) { const { peerPubKey, address } = uri; - let timeout: NodeJS.Timeout | undefined; try { - timeout = setTimeout(() => { - throw new Error('connectPeer has timed out'); - }, CONNECT_TIMEOUT); await this.connectPeer(peerPubKey, address); return true; } catch (e) { if (e.message && e.message.includes('already connected')) { return true; } - this.logger.trace(`connectPeer failed: ${e}`); - } finally { - timeout && clearTimeout(timeout); + this.logger.trace(`connectPeer to ${uri} failed: ${e}`); } } return false;