From 487b3501a54e5479972a7982fe1eb154f0447b58 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Mon, 8 Aug 2022 21:51:01 +0700 Subject: [PATCH] context: Revert "context: use CompareAndSwap in cancelCtx.Done" This reverts commit 964f0c7a306998256f1c5a5fd78fc457a972f001. Reason: cause increasing timeout in crypto/tls tests on race builders. Change-Id: Id16d4fcd19c2ca2e89ad4d0c9d55ef1105b19c76 Reviewed-on: https://go-review.googlesource.com/c/go/+/422035 TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh Auto-Submit: Cuong Manh Le Run-TryBot: Cuong Manh Le Reviewed-by: Michael Pratt --- src/context/context.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/context/context.go b/src/context/context.go index 04ac080402..1070111efa 100644 --- a/src/context/context.go +++ b/src/context/context.go @@ -360,8 +360,14 @@ func (c *cancelCtx) Done() <-chan struct{} { if d != nil { return d.(chan struct{}) } - c.done.CompareAndSwap(nil, make(chan struct{})) - return c.done.Load().(chan struct{}) + c.mu.Lock() + defer c.mu.Unlock() + d = c.done.Load() + if d == nil { + d = make(chan struct{}) + c.done.Store(d) + } + return d.(chan struct{}) } func (c *cancelCtx) Err() error { -- 2.50.0