-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
runtime: under edge conditions, select fails to read from time.After() channel #14561
Comments
I have stripped as much as I can out of the codebase and posted it to a new repo: https://github.com/bobziuchkovski/golang-select-repro The code itself is now basically gibberish, but it does reproduce the issue. On my laptop, I get the hanging select about 1 out of every 8 tries now. I'm not sure if it's related or not, but I can also trigger an internal compiler error, hdr := NewBuffer()
hdr.WriteString("blah") to NewBuffer() |
I updated the issue description with a bit more info on where the panic is triggered, where the hanging select is triggered, etc. In short: The select in question is in logger.go on line 110. The panic is triggered in main.go on line 45. If I comment-out that panic, I can't reproduce the hanging select. The close method with the select in question is triggered indirectly via line 40 of main.go. |
Hey @bobziuchkovski, would it be possible for you to try to (separately from this issue) minimize the repro for the internal compiler error and open that as a separate issue? |
I think this is #10958 (or one of the many similar "infinite loops are bad" known issues). Namely, your FYI, here's how I diagnosed this:
After changing |
@mdempsky Thank you so much for the time you put into debugging that! I was just reviewing the live project code and I fixed the infinite loop some time ago, but didn't realize that was the cause of the select race. I'm sorry you ended up wasting time on a duplicate bug, but I really appreciate both the time you spent as well as the diagnostic steps you shared above. That is an incredibly useful diagnostic procedure. Thanks again! |
What version of Go are you using (
go version
)?Tested on go1.6 darwin/amd64 and go1.6 linux/amd64
What operating system and processor architecture are you using (
go env
)?Mac:
Linux:
What did you do?
What did you expect to see?
I should see "before select" printed. Then after 1 second, I should see "timeout occurred" printed.
What did you see instead?
I see "before select" printed. Nothing else prints and the program never exits. This is definitely the only function in my code that prints "before select", so the close method is called, but the channel read from the time.After channel never happens. I've noticed the program spins my CPU at 100% while I'm waiting for the timeout that never occurs.
Other
I can only reproduce this when I add a panic() to one of my functions and recover from the panic. The "close" method shown above runs on program termination, after the panic recovery. If I modify the panicking code to return nil in place of the panic, I can't reproduce. That portion of code is outside of this close method. I also can't reproduce if I remove the select and read directly from the channel.
I ripped apart my code trying to find the cause of the hanging select. I uploaded a functioning but mangled/stripped copy of the code to https://github.com/bobziuchkovski/golang-select-repro. The code itself hardly makes sense anymore, but it runs and reproduces the hanging select about 1 in 8 times on my laptop.
The select in question is in logger.go on line 110. The panic is triggered in main.go on line 45. If I comment-out that panic, I can't reproduce the hanging select. The close method with the select in question is triggered indirectly via line 40 of main.go
The text was updated successfully, but these errors were encountered: