]> Cypherpunks repositories - gostls13.git/commit
context: don't return the wrong error when Cause races cancellation
authorDamien Neil <dneil@google.com>
Fri, 6 Jun 2025 22:38:28 +0000 (15:38 -0700)
committerDamien Neil <dneil@google.com>
Tue, 25 Nov 2025 01:02:35 +0000 (17:02 -0800)
commit1a53ce9734c0b2a3e2a9814e75949ea77a978143
treec265e2e55df8bec78f1ece2451af4de7eccce53e
parentc6f882f6c58ed56fa4bd2d8256ec55d9992c3583
context: don't return the wrong error when Cause races cancellation

Check to see if a context is canceled at all
before checking for the cancellaion cause.
If we can't find a cause, use the original error.

Avoids a data race where we look for a cause,
find none (because the context is not canceled),
the context is canceled,
and we then return ctx.Err() (even though there is now a cause).

Fixes #73390

Change-Id: I97f44aef25c6b02871d987970abfb4c215c5c80e
Reviewed-on: https://go-review.googlesource.com/c/go/+/679835
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/context/context.go