From 37d974cae9a0bc06ccdf26b0ff16f14ded1eac02 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 2 Nov 2019 21:42:51 +1100 Subject: stmutil.ContextDoneVar: Return true Var if the context is already done This prevents needless races, such as in some of the rate limiting tests. --- stmutil/context.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'stmutil/context.go') diff --git a/stmutil/context.go b/stmutil/context.go index 49f211c..75e3f8a 100644 --- a/stmutil/context.go +++ b/stmutil/context.go @@ -7,6 +7,9 @@ import ( ) func ContextDoneVar(ctx context.Context) (*stm.Var, func()) { + if ctx.Err() != nil { + return stm.NewVar(true), func() {} + } ctx, cancel := context.WithCancel(ctx) _var := stm.NewVar(false) go func() { -- cgit v1.2.3