Skip to content

runtime: val, ok = <- someChannel inside of select causes ok to be false on empty channel but not closed #8347

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

Closed
gopherbot opened this issue Jul 9, 2014 · 7 comments
Milestone

Comments

@gopherbot
Copy link
Contributor

by Chance.Zibolski:

Firstly, I want to mention this issue was found in go 1.2.2 and resolved in go 1.3, but
because I was unable to find a bug, or any mention of this problem in the release notes,
I was not very confident that the Go authors were aware of the bug existing or getting
fixed, because the lack of disclosure related to the issue.

The issue violates the spec "The value of ok is true if the value received was
delivered by a successful send operation to the channel, or false if it is a zero value
generated because the channel is closed and empty."

The actual behavior in go 1.2.2 is that the value is false when the channel is closed
*OR* empty.

Because there may be code running on 1.2.2 which expects the behavior to be the
"OR" (even though it isnt according the spec), I would have expected this to
be announced on the release, much like how map iteration became random.

I also expect that there would be a test to verify, and assert the proper behavior, but
I'm also unsure of that.

What does 'go version' print?

go1.2.2 linux/amd64

What steps reproduce the problem?

Use the val, ok idiom to receive from a non-closed channel which is empty, inside of a
select structure with a default case.

http://play.golang.org/p/zvPKOQeOD5
https://gist.github.com/ecnahc515/9c42754b8c4dfc27500f

What happened?

The value of okay was set to false.

What should have happened instead?

The value of okay should remain true.

Please provide any additional information below.

After talking to some people in #go-nuts who bisected, they seem to think the issue was
fixed here: https://golang.org/cl/83000048
@dominikh
Copy link
Member

dominikh commented Jul 9, 2014

Comment 1:

To save some people the effort:
Go 1.0.2 (yes, that old) already had the wrong behaviour.
https://golang.org/cl/83000048 is the CL that eventually changed it.

@gopherbot
Copy link
Contributor Author

Comment 2:

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

@gopherbot
Copy link
Contributor Author

Comment 3 by Chance.Zibolski:

If there is a test and as I've found, its been fixed then this could be closed. However
I'm very surprised the was no announcement about this bug somewhere. Maybe I'm blind
though.

@ianlancetaylor
Copy link
Contributor

Comment 4:

Labels changed: added repo-main, release-go1.4.

@robpike
Copy link
Contributor

robpike commented Jul 18, 2014

Comment 6:

This is reporting a bug that has been fixed in 1.3. I am unsure what the requester is
asking for. Is it just a test? If so, please submit a CL to add a test.

@gopherbot
Copy link
Contributor Author

Comment 7 by Chance.Zibolski:

I'm not writing a test, but yes, I filed a bug because I didn't have much confidence
this bug was an intentionally fixed after reviewing what might have fixed this.

@minux
Copy link
Member

minux commented Jul 19, 2014

Comment 8:

This issue was closed by revision 2296928.

Status changed to Fixed.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
Fixes golang#8347.

LGTM=dave
R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/109600044
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
Fixes golang#8347.

LGTM=dave
R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/109600044
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

6 participants