You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation for context.Cause says that if a context was canceled other than via a call to CancelCauseFunc, then "Cause(c) returns the same value as c.Err()". However, that is not true today for a custom context. CC @Sajmani
Should that be backported to Go 1.20 where this behaviour has been introduced or is there a possible workaround for that issue that I am missing to see?
It's kind of an edge case: code that has a custom Context type and calls context.Cause on that type. There isn't a lot of reason to call context.Cause on a Context that wasn't created by context.WithCancelCause, and by definition that does not return a custom context. So this issue doesn't seem to meet the requirements outlined at https://go.dev/wiki/MinorReleases. Happy to hear counter-arguments.
It's kind of an edge case: code that has a custom Context type and calls context.Cause on that type.
I don't think it's such an edge case. I hit this while working on a library that does some intensive work and regularly checks for the context cancellation with if err := context.Cause(ctx); err != nil {.
The library doesn't know the type of the context that it has been provided, so in the case of a custom context it won't detect its cancellation and will keep executing.
The documentation for
context.Cause
says that if a context was canceled other than via a call toCancelCauseFunc
, then "Cause(c)
returns the same value asc.Err()
". However, that is not true today for a custom context. CC @SajmaniHere is a test:
This fails with
The text was updated successfully, but these errors were encountered: