From dd2ead102246066e3b21d01cea769c9cc7bc4374 Mon Sep 17 00:00:00 2001 From: Eugene Siegel Date: Mon, 6 Nov 2023 10:14:39 -0500 Subject: [PATCH 1/2] routing: launch fetchFundingTx in goroutine so router can exit This commit introduces a wrapper function fetchFundingTxWrapper which calls fetchFundingTx in a goroutine. This is to avoid an issue with pruned nodes where the router is attempting to stop, but the prunedBlockDispatcher is waiting to connect to peers that can serve the block. This can cause the shutdown process to hang until we connect to a peer that can send us the block. --- routing/router.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/routing/router.go b/routing/router.go index 0b09003f1..5b52cfb8f 100644 --- a/routing/router.go +++ b/routing/router.go @@ -1552,7 +1552,7 @@ func (r *ChannelRouter) processUpdate(msg interface{}, // to obtain the full funding outpoint that's encoded within // the channel ID. channelID := lnwire.NewShortChanIDFromInt(msg.ChannelID) - fundingTx, err := r.fetchFundingTx(&channelID) + fundingTx, err := r.fetchFundingTxWrapper(&channelID) if err != nil { // In order to ensure we don't erroneously mark a // channel as a zombie due to an RPC failure, we'll @@ -1762,6 +1762,36 @@ func (r *ChannelRouter) processUpdate(msg interface{}, return nil } +// fetchFundingTxWrapper is a wrapper around fetchFundingTx, except that it +// will exit if the router has stopped. +func (r *ChannelRouter) fetchFundingTxWrapper(chanID *lnwire.ShortChannelID) ( + *wire.MsgTx, error) { + + txChan := make(chan *wire.MsgTx, 1) + errChan := make(chan error, 1) + + go func() { + tx, err := r.fetchFundingTx(chanID) + if err != nil { + errChan <- err + return + } + + txChan <- tx + }() + + select { + case tx := <-txChan: + return tx, nil + + case err := <-errChan: + return nil, err + + case <-r.quit: + return nil, ErrRouterShuttingDown + } +} + // fetchFundingTx returns the funding transaction identified by the passed // short channel ID. // From 41e251b0d781684425cadfb63b498f786b9e1151 Mon Sep 17 00:00:00 2001 From: Eugene Siegel Date: Thu, 30 Nov 2023 10:35:11 -0500 Subject: [PATCH 2/2] release-notes: update for 0.17.3 --- docs/release-notes/release-notes-0.17.3.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/release-notes/release-notes-0.17.3.md b/docs/release-notes/release-notes-0.17.3.md index 1cbfe8cf8..8041603b4 100644 --- a/docs/release-notes/release-notes-0.17.3.md +++ b/docs/release-notes/release-notes-0.17.3.md @@ -26,6 +26,8 @@ * [Fixed](https://github.com/lightningnetwork/lnd/pull/8220) a loop variable issue which may affect programs built using go `v1.20` and below. +* [An issue where LND would hang on shutdown has been fixed.](https://github.com/lightningnetwork/lnd/pull/8151) + # New Features ## Functional Enhancements ## RPC Additions @@ -47,4 +49,5 @@ ## Tooling and Documentation # Contributors (Alphabetical Order) +* Eugene Siegel * Yong Yu