Break The Golang Context Chain
And enabling a context to be used after cancellation
Go 1.21 Update: Apparently alongside me writing this article, the Go project was tracking this very same issue. Comments in the thread bring up some very valid concerns with this pattern beyond the caveats I cover below, but ultimately the feature is now part of the Go 1.21 changeset as context.WithoutCancel. Recently, I recalled a useful pattern that’s cropped up a few times at work. API handlers (think http.Handler), include a context.