From 861412529d46fba196be0650ddd2fdf26060bec1 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 11 Nov 2017 15:00:45 -0800 Subject: [PATCH] lnwallet: add select on quit when waiting for job from sigPool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit we ensure that the channel is always able to exit by adding a select statement with a quit case when we’re waiting on the result of a job that was previously sent into the sigPool. --- lnwallet/channel.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 9016c8f4..a366d550 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -2938,16 +2938,19 @@ func (lc *LightningChannel) SignNextCommitment() (*btcec.Signature, []*btcec.Sig // gather each of the signatures in order. htlcSigs := make([]*btcec.Signature, 0, len(sigBatch)) for _, htlcSigJob := range sigBatch { - jobResp := <-htlcSigJob.resp + select { + case jobResp := <-htlcSigJob.resp: + // If an error occurred, then we'll cancel any other + // active jobs. + if jobResp.err != nil { + close(cancelChan) + return nil, nil, err + } - // If an error occurred, then we'll cancel any other active - // jobs. - if jobResp.err != nil { - close(cancelChan) - return nil, nil, err + htlcSigs = append(htlcSigs, jobResp.sig) + case <-lc.quit: + return nil, nil, fmt.Errorf("channel shutting down") } - - htlcSigs = append(htlcSigs, jobResp.sig) } // As we're about to proposer a new commitment state for the remote @@ -3432,9 +3435,14 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSig *btcec.Signature, for i := 0; i < len(verifyJobs); i++ { // In the case that a single signature is invalid, we'll exit // early and cancel all the outstanding verification jobs. - if err := <-verifyResps; err != nil { - close(cancelChan) - return fmt.Errorf("invalid htlc signature: %v", err) + select { + case err := <-verifyResps: + if err != nil { + close(cancelChan) + return fmt.Errorf("invalid htlc signature: %v", err) + } + case <-lc.quit: + return fmt.Errorf("channel shutting down") } }