From d39410cc01b041cfbfa0c8fd63dd05ffcc513326 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 3 Aug 2017 16:40:08 -0700 Subject: [PATCH] rpc: wrap canceling a breach watch in a select case --- rpcserver.go | 6 +++++- server.go | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 5d947c59..727268f3 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -613,7 +613,11 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest, r.server.htlcSwitch.RemoveLink(chanID) } - r.server.breachArbiter.settledContracts <- chanPoint + select { + case r.server.breachArbiter.settledContracts <- chanPoint: + case <-r.quit: + return fmt.Errorf("server shutting down") + } // With the necessary indexes cleaned up, we'll now force close // the channel. diff --git a/server.go b/server.go index fdb19e89..b201a7be 100644 --- a/server.go +++ b/server.go @@ -165,6 +165,7 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl, s.htlcSwitch = htlcswitch.New(htlcswitch.Config{ LocalChannelClose: func(pubKey []byte, request *htlcswitch.ChanClose) { + s.peersMtx.RLock() peer, ok := s.peersByPub[string(pubKey)] s.peersMtx.RUnlock()