From 03a070659315b18a9c350f9d8498e22e9681d16e Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 25 Feb 2020 12:20:17 -0300 Subject: [PATCH] chancloser: unregister channel before db modification This fixes a race during channel closing, where the last channel state update was still not finished when we set the channel close bit in the database. This lead to a flake during integration tests, where the last state update would not finish, and the channel wasn't closes successfully. We fix it by first unregistering the channel, making sure it is removed fully from the link before doing the db modification. --- chancloser.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/chancloser.go b/chancloser.go index 00dff1bf..bcd0ec8b 100644 --- a/chancloser.go +++ b/chancloser.go @@ -223,6 +223,10 @@ func (c *channelCloser) initChanShutdown() (*lnwire.Shutdown, error) { "close: %v", c.chanPoint, err) } + // Before returning the shutdown message, we'll unregister the channel + // to ensure that it isn't seen as usable within the system. + c.cfg.unregisterChannel(c.cid) + // Before continuing, mark the channel as cooperatively closed with a // nil txn. Even though we haven't negotiated the final txn, this // guarantees that our listchannels rpc will be externally consistent, @@ -233,12 +237,6 @@ func (c *channelCloser) initChanShutdown() (*lnwire.Shutdown, error) { return nil, err } - // Before returning the shutdown message, we'll unregister the channel - // to ensure that it isn't seen as usable within the system. - // - // TODO(roasbeef): fail if err? - c.cfg.unregisterChannel(c.cid) - peerLog.Infof("ChannelPoint(%v): sending shutdown message", c.chanPoint) return shutdown, nil