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

go.blog/context: Context blog post Gorilla example has a subtle bug #8443

Closed
gopherbot opened this issue Jul 29, 2014 · 5 comments
Closed

go.blog/context: Context blog post Gorilla example has a subtle bug #8443

gopherbot opened this issue Jul 29, 2014 · 5 comments

Comments

@gopherbot
Copy link

http://blog.golang.org/context has an example
http://blog.golang.org/context/gorilla/gorilla.go
that does

var reqKey struct{}

    if key == &reqKey {

However, http://golang.org/ref/spec#Comparison_operators says

"Pointers to distinct zero-size variables may or may not be equal."

Which means multiple parties trying to be clever and using pointers to struct{} values
may end up colliding.
@adg
Copy link
Contributor

adg commented Jul 30, 2014

Comment 1:

I seem to recall this was originally an int?

Owner changed to @Sajmani.

Status changed to Accepted.

@adg
Copy link
Contributor

adg commented Jul 30, 2014

Comment 2:

Labels changed: added repo-blog.

@Sajmani
Copy link
Contributor

Sajmani commented Jul 30, 2014

Comment 3:

Yes, I changed it to use the address of an empty struct var when I updated the example
to use just a single key.
The example server still works because there's only a single context key used in the
example, but this is a bug.
I will send a CL to fix the affected examples in the blog post (gorilla.go and
userip.go).
Note that the context godoc uses an int key and so is ok.

@gopherbot
Copy link
Author

Comment 4:

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

@Sajmani
Copy link
Contributor

Sajmani commented Jul 30, 2014

Comment 5:

This issue was closed by revision golang/blog@9cab33c.

Status changed to Fixed.

minux pushed a commit to Go-zh/blog that referenced this issue Dec 14, 2014
key, as this is not guaranteed to be unique.

Fixes golang/go#8443.

LGTM=campoy
R=adg, campoy
CC=dsymonds, golang-codereviews
https://golang.org/cl/121890043
@golang golang locked and limited conversation to collaborators Jun 25, 2016
gopherbot pushed a commit to golang/website that referenced this issue May 26, 2021
… a context

key, as this is not guaranteed to be unique.

Fixes golang/go#8443.

LGTM=campoy
R=adg, campoy
CC=dsymonds, golang-codereviews
https://golang.org/cl/121890043
X-Blog-Commit: 9cab33ca8e480d9a24efdd84433601a80f9c7fb5
@rsc rsc unassigned Sajmani Jun 23, 2022
passionSeven added a commit to passionSeven/website that referenced this issue Oct 18, 2022
… a context

key, as this is not guaranteed to be unique.

Fixes golang/go#8443.

LGTM=campoy
R=adg, campoy
CC=dsymonds, golang-codereviews
https://golang.org/cl/121890043
X-Blog-Commit: 9cab33ca8e480d9a24efdd84433601a80f9c7fb5
This issue was closed.
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

3 participants