From a185163c5779faaaea9ea29c7c8626c7d26295ca Mon Sep 17 00:00:00 2001 From: "M. J. Fromberger" Date: Mon, 21 Feb 2022 04:54:43 -0800 Subject: [PATCH] light: avert a data race (#7888) --- light/detector.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/light/detector.go b/light/detector.go index c0a5bd2c1..1d7a066cb 100644 --- a/light/detector.go +++ b/light/detector.go @@ -26,6 +26,8 @@ import ( // If there are no conflictinge headers, the light client deems the verified target header // trusted and saves it to the trusted store. func (c *Client) detectDivergence(ctx context.Context, primaryTrace []*types.LightBlock, now time.Time) error { + c.providerMutex.Lock() + defer c.providerMutex.Unlock() if len(c.witnesses) < 1 { return nil } @@ -40,9 +42,6 @@ func (c *Client) detectDivergence(ctx context.Context, primaryTrace []*types.Lig c.logger.Debug("running detector against trace", "endBlockHeight", lastVerifiedHeader.Height, "endBlockHash", lastVerifiedHeader.Hash, "length", len(primaryTrace)) - c.providerMutex.Lock() - defer c.providerMutex.Unlock() - // launch one goroutine per witness to retrieve the light block of the target height // and compare it with the header from the primary errc := make(chan error, len(c.witnesses))