From 4e093a6cd29bc9f748fdeb5401836060039017f0 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Mon, 20 Aug 2018 22:03:56 -0700 Subject: [PATCH] htlcswitch/switch: shutdown links concurrently --- htlcswitch/switch.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 4a547e59..b7df23f8 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -1401,9 +1401,17 @@ func (s *Switch) htlcForwarder() { // Now that all pending and live links have been removed from // the forwarding indexes, stop each one before shutting down. + // We'll shut them down in parallel to make exiting as fast as + // possible. + var wg sync.WaitGroup for _, link := range linksToStop { - link.Stop() + wg.Add(1) + go func(l ChannelLink) { + defer wg.Done() + l.Stop() + }(link) } + wg.Wait() // Before we exit fully, we'll attempt to flush out any // forwarding events that may still be lingering since the last