From the documentation of func (r *Request) Context() context.Context
in the net/http
package:
For incoming server requests, the context is canceled when the client's connection closes, the request is canceled (with HTTP/2), or when the ServeHTTP method returns.
What is the correct thing to do if I want to complete work related to the request after the ServeHTTP
method has returned, for example emitting notifications? I'd like to preserve the context chain in terms of values but simply passing the context originally returned by the above method to the message queue submission API doesn't work as the context may be cancelled before it completes.
Is there an easy way to derive just the values in a context chain without deadline or cancellation? I can manually copy values I have the keys for, but other things that rely on context continuity, like trace, will be absent.
Thanks in advance for any answers.