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

spec: Unexpect deadlock on select multi channel #23728

Closed
ariesdevil opened this issue Feb 7, 2018 · 5 comments
Closed

spec: Unexpect deadlock on select multi channel #23728

ariesdevil opened this issue Feb 7, 2018 · 5 comments

Comments

@ariesdevil
Copy link

ariesdevil commented Feb 7, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.3 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ariesdevil/Dropbox/workspace/go_workspace"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/h2/xl15t9g94tgfwclshzl086bh0000gp/T/go-build125147941=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

code: https://play.golang.org/p/8rcO11QS8un

What did you expect to see?

I think it should not deadlock.

What did you see instead?

fatal error: all goroutines are asleep - deadlock!

goroutine 1 [chan receive]:
main.main()
	/tmp/sandbox682002440/main.go:23 +0x80
@ianlancetaylor
Copy link
Contributor

A select statement evaluates all values to be sent on a channel before choosing a case. In this example this means that <-source is evaluated each time you enter the select. After the first two times, the select blocks waiting for a value to arrive. The other goroutine then tries to send on idle, but nothing is listening, so it blocks. So all goroutines are asleep.

Closing because this is working as expected.

@ariesdevil
Copy link
Author

@ianlancetaylor thx!

@ariesdevil
Copy link
Author

ariesdevil commented Feb 7, 2018

https://play.golang.org/p/fJXhK8w22uu
Above code sometimes run perfect and sometimes deadlock on my machine.
2018-02-07 22 10 22

But if I put it in a goroutine, the result is confused:

https://play.golang.org/p/oUmMr8TM2sz success
https://play.golang.org/p/54eLI7x5FwD failed

notice line 25 when I use

case worker := <-source:
        idle <- worker

instead of:

case idle <- <-source:

it works.

@ianlancetaylor
Copy link
Contributor

Unlike some other projects, we don't use the issue tracker for discussion. We only use it for bug reports. Please take any discussion to a forum; see https://golang.org/wiki/Questions. Thanks.

@ariesdevil
Copy link
Author

@ianlancetaylor OK.

@mikioh mikioh changed the title Unexpect deadlock on select multi channel spec: Unexpect deadlock on select multi channel Feb 21, 2018
@golang golang locked and limited conversation to collaborators Feb 21, 2019
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