Always capture the return value of context.WithValue to use the new context and avoid memory leaks.
Always use the return values from context.WithValue to ensure the new context is used and to prevent memory leaks from holding onto the parent context. The unusedresult analyzer explicitly flags calls to context.WithValue where the result is ignored because the function returns a new context that must be propagated down the call stack.
ctx := context.WithValue(parentCtx, key, value)
// Use ctx for subsequent operations, not parentCtx
myFunc(ctx)
When you add data to a context, the function creates a brand new context object containing that data. If you ignore the result, your code keeps using the old context without the new data, and the new context object gets stuck in memory until the program ends. Think of it like making a copy of a document with a note added; if you throw away the copy and keep using the original, the note is lost and the copy is wasted paper.