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

cmd/vet: add check for Context.WithValue(_, string, _) #17293

Closed
bradfitz opened this issue Sep 30, 2016 · 6 comments
Closed

cmd/vet: add check for Context.WithValue(_, string, _) #17293

bradfitz opened this issue Sep 30, 2016 · 6 comments

Comments

@bradfitz
Copy link
Contributor

Using a context.Context Value key of type string is a terrible idea and walks into the minefield of a global namespace. We should've outlawed it from day 1.

All context value keys should be made from user-defined types.

Also disallow int, bool, etc. But string is what I usually see.

@bradfitz bradfitz added this to the Go1.8 milestone Sep 30, 2016
@mdlayher
Copy link
Member

I'd be happy to give this a try.

@bradfitz
Copy link
Contributor Author

Thanks.

@bradfitz bradfitz reopened this Sep 30, 2016
@mdlayher
Copy link
Member

Submitted an initial CL here: https://go-review.googlesource.com/c/30084/.

I suspect there's probably more I can do, but I would appreciate some review before I pursue this issue further.

@robpike
Copy link
Contributor

robpike commented Sep 30, 2016

This is not a correctness issue and so should not be fixed in vet. It's a better candidate for lint.

@gopherbot
Copy link

CL https://golang.org/cl/30084 mentions this issue.

@dsnet
Copy link
Member

dsnet commented Oct 1, 2016

Merged as golang/lint@c6242af

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

No branches or pull requests

5 participants