Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better to keep context.WithValue constant #5665

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

polyrabbit
Copy link
Contributor

In stdlib, context.WithValue returns a derived context that points to the parent Context, and the parent Context is not modified.

In JuiceFS, context.WithValue mutates itself by stacking the Context field. This is error-prone as no one can clean the stack chain.

Especially in the gateway scenario where meta.Context is a global variable - its value chain can grow infinitely as gateway runs long enough. This causes a memory leak and makes searching for a non-existent key very expensive.

It's better to follow best practices in the Go community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant