-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: Stack trace of bound method of embedded interface inside slice causes an infinite loop #51401
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
Comments
Passes with 1.17 and gccgo, fails with 1.18. |
The method wrapper The infinite loop comes from that in that malformed inline tree, the "parent PC" of the entry of |
The method wrapper is generated at https://cs.opensource.google/go/go/+/master:src/cmd/compile/internal/walk/closure.go;l=238 , which sets Pos conditionally. For this case the condition seems false, which leaves base.Pos whatever it is before.
cc @mdempsky |
I think just historical. If changing it to AutogeneratedPos works and fixes this issue, I think doing that instead sounds good. Edit: I think maybe it does affect where some diagnostic messages get printed, which then affects test/run.go test expectations? I feel like that's why I always punt on trying to fix it. I've definitely looked at this code several times in the past and thought the position handling was sketchy.
|
Thanks. Do you know a case where using the Pos of the declaration produces better diagnoses? all.bash passes if I change it to use AutogeneratedPos. Or perhaps we could take a hybrid approach, where we use the declaration Pos if it is known, otherwise AutogeneratedPos? In any case, it should not be a Pos that has inline information.
Thanks for the clarification. Yeah, I was thinking something like that. |
Change https://go.dev/cl/388794 mentions this issue: |
The CL above tries to use AutogeneratedPos. It seems to work. Not sure if this is the best solution, though. |
If the trybots are happy with AutogeneratedPos, then I'm happy. :) |
@cherrymui @mdempsky, thanks for the quick diagnosis and fix! This issue appears to be tagged for the Go 1.19 milestone. |
Change https://go.dev/cl/388918 mentions this issue: |
…value wrapper We use AutogeneratedPos for most compiler-generated functions. But for method value wrappers we currently don't. Instead, we use the Pos for their (direct) declaration if there is one, otherwise not set it in methodValueWrapper, which will probably cause it to inherit from the caller, i.e. the Pos of that method value expression. If that Pos has inline information, it will cause the method wrapper to have bogus inline information, which could lead to infinite loop when printing a stack trace. Change it to use AutogeneratedPos instead. Fixes #51401. Change-Id: I398dfe85f9f875e1fd82dc2f489dab63ada6570d Reviewed-on: https://go-review.googlesource.com/c/go/+/388794 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> (cherry picked from commit b0db2f0) Reviewed-on: https://go-review.googlesource.com/c/go/+/388918 Trust: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
(Apologies for the overly long title, but I've only been able to isolate this to that specific case.)
What version of Go are you using (
go version
)?Tested on 1.18rc1 and master.
Does this issue reproduce with the latest release?
Not with the latest stable release (Go 1.17.7). Yes with the latest unstable release.
What operating system and processor architecture are you using (
go env
)?Tested on macOS with Go 1.18rc1, and on Linux with 1.18rc1 and master.
go env
OutputmacOS
Linux
What did you do?
In the course of testing Go 1.18rc1 on our internal codebase, I ran into a test that timed out. Upon investigation, I was able to isolate the issue to code with roughly the following structure:
There are two interfaces Outer and Inner where Outer only embeds Inner. Given a reference to Outer, a function builds a slice with a bound reference to the method defined on Inner. A different function takes this slice and calls that bound method. The method attempts to capture its stack trace.
The following code reproduces this issue on Go 1.18rc1 and master.
https://go.dev/play/p/l7rdkzfwX3I?v=gotip
What did you expect to see?
The code to run and return instantly.
What did you see instead?
It loops forever.
If I terminate it with SIGQUIT (Ctrl-\) the core dump includes the following:
Core dump
Worth noting that the core dump also loops infinitely—or at least for 5 seconds (I didn't give it longer)—on reporting this line of code:
Additional information
Worth noting that if I run the same with delve, it passes:
The text was updated successfully, but these errors were encountered: