From 55b53555e93d30ad1c1ef5a841650287f99aea44 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 21 Nov 2022 13:07:56 +0100 Subject: [PATCH] multi: improve readability of goroutine defers This commit fixes the readability of some of the defer calls in goroutines by making sure the defer stands out properly. --- discovery/gossiper.go | 2 ++ funding/manager.go | 1 + htlcswitch/switch.go | 1 + lntest/itest/utils.go | 1 + rpcperms/middleware_handler.go | 3 ++- sweep/sweeper.go | 1 + ticker/force.go | 1 + watchtower/wtclient/session_queue.go | 1 + 8 files changed, 10 insertions(+), 1 deletion(-) diff --git a/discovery/gossiper.go b/discovery/gossiper.go index bceb3755c..bd2d3b605 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -1325,6 +1325,7 @@ func (d *AuthenticatedGossiper) networkHandler() { d.wg.Add(1) go func() { defer d.wg.Done() + log.Infof("Broadcasting %v new announcements in %d sub batches", len(announcementBatch), len(splitAnnouncementBatch)) @@ -2947,6 +2948,7 @@ func (d *AuthenticatedGossiper) handleAnnSig(nMsg *networkMsg, d.wg.Add(1) go func() { defer d.wg.Done() + log.Debugf("Received half proof for channel "+ "%v with existing full proof. Sending"+ " full proof to peer=%x", diff --git a/funding/manager.go b/funding/manager.go index d9eeac9a0..b33b18ced 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -1969,6 +1969,7 @@ func (f *Manager) handleFundingAccept(peer lnpeer.Peer, f.wg.Add(1) go func() { defer f.wg.Done() + f.waitForPsbt(psbtIntent, resCtx, pendingChanID) }() diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 8b2120d3e..34997ac82 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -1742,6 +1742,7 @@ func (s *Switch) htlcForwarder() { wg.Add(1) go func(l ChannelLink) { defer wg.Done() + l.Stop() }(link) } diff --git a/lntest/itest/utils.go b/lntest/itest/utils.go index c2539b73b..dd03ac40b 100644 --- a/lntest/itest/utils.go +++ b/lntest/itest/utils.go @@ -405,6 +405,7 @@ func subscribeChannelNotifications(ctxb context.Context, t *harnessTest, chanUpdates := make(chan *lnrpc.ChannelEventUpdate, 20) go func() { defer cancelFunc() + for { select { case <-quit: diff --git a/rpcperms/middleware_handler.go b/rpcperms/middleware_handler.go index 1e9d16b56..b18fc0d16 100644 --- a/rpcperms/middleware_handler.go +++ b/rpcperms/middleware_handler.go @@ -180,8 +180,9 @@ func (h *MiddlewareHandler) Run() error { // request to the client). h.wg.Add(1) go func() { + defer h.wg.Done() + h.receiveResponses(errChan, responses) - h.wg.Done() }() return h.sendInterceptRequests(errChan, responses) diff --git a/sweep/sweeper.go b/sweep/sweeper.go index d34ee50b9..5957b51ac 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -1415,6 +1415,7 @@ func (s *UtxoSweeper) waitForSpend(outpoint wire.OutPoint, s.wg.Add(1) go func() { defer s.wg.Done() + select { case spend, ok := <-spendEvent.Spend: if !ok { diff --git a/ticker/force.go b/ticker/force.go index 016e37020..dff99dabd 100644 --- a/ticker/force.go +++ b/ticker/force.go @@ -39,6 +39,7 @@ func NewForce(interval time.Duration) *Force { m.wg.Add(1) go func() { defer m.wg.Done() + for { select { case t := <-m.ticker: diff --git a/watchtower/wtclient/session_queue.go b/watchtower/wtclient/session_queue.go index 7d98ec86f..a5c570a71 100644 --- a/watchtower/wtclient/session_queue.go +++ b/watchtower/wtclient/session_queue.go @@ -689,6 +689,7 @@ func (s *sessionQueueSet) ApplyAndWait(getApply func(*sessionQueue) func()) { wg.Add(1) go func(sq *sessionQueue) { defer wg.Done() + getApply(sq)() }(sessionq) }