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

reflect: allows closing read only channels #61445

Closed
marktayl opened this issue Jul 19, 2023 · 1 comment
Closed

reflect: allows closing read only channels #61445

marktayl opened this issue Jul 19, 2023 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@marktayl
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.20.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes, including play.golang.org

What operating system and processor architecture are you using (go env)?

-- irrelevant (MacOs Monterey 12.6.6 on Intel) --

What did you do?

ch := make(<-chan string)
close(ch) // generates a compile-time error "cannot close receive-only channel"
reflect.ValueOf(ch).Close()  // will actually close the channel

https://go.dev/play/p/OkmaDlPn47t

What did you expect to see?

Expected reflect.ValueOf(ch).Close() to panic, like reflect.ValueOf(ch).Send(reflect.ValueOf("qq")) does when sending on a receive-only channel.

What did you see instead?

The receive-only channel was closed.

@seankhliao seankhliao changed the title reflect.Close() on a receive-only channel works (it shouldn't) reflect: allows closing read only channels Jul 19, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 19, 2023
@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 19, 2023
mauri870 added a commit to mauri870/go that referenced this issue Jul 19, 2023
It is possible to call `reflect.ValueOf(ch).Close()`
on a recv-only channel. Following the same semantics as send
it should result in a panic.

Fixes golang#61445
@gopherbot
Copy link

Change https://go.dev/cl/511295 mentions this issue: reflect: panic on recv channel close

mauri870 added a commit to mauri870/go that referenced this issue Jul 20, 2023
It is possible to call `reflect.ValueOf(ch).Close()`
on a recv-only channel. Following the same semantics as send
it should result in a panic.

Fixes golang#61445
@dmitshur dmitshur added this to the Go1.22 milestone Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants