context: Clarify whether Values are retained after cancellation #57565
Labels
Documentation
Issues describing a change to documentation.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Also present on tip.
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Darwin arm64, but very confident it is not a system/processor architecture-specific issue.
What did you do?
Check https://pkg.go.dev/context#WithCancel
What did you expect to see?
Whether the Values of a Context are the resources released when a Context is canceled.
What did you see instead?
Issue template taken care of, the crux of this issue is that I was browsing #19643 and realized that my problem with canceled Contexts--that once canceled, I can't count on accessing any of the Values I've stored in them using WithValue (logger, etc) anymore--wasn't one people were talking about. Reading that issue, it honestly seemed like people way more familiar with Go than I am were of the distinct impression you could access Values after canceling a Context.
So I dug into why I thought I couldn't, and tracked it back to that comment--that resources associated with the Context would released. But on rereading, I'm noting it doesn't say Values.... but it doesn't not say Values, either?
My two goals for this ticket, of which one would suffice but two would be ideal, are:
I'm willing to accept that I'm the only one with this confusion and therefore it doesn't need to be in the docs, I just don't want to accidentally rely on implementation details. :)
Thanks!
[edit] Play link as a demonstration, in case I'm being unclear: https://go.dev/play/p/Fw9O23Agl7c
The text was updated successfully, but these errors were encountered: