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

runtime: recover calls in loop body of ranging over iterators doesn't take effect #71685

Open
zigo101 opened this issue Feb 12, 2025 · 8 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@zigo101
Copy link

zigo101 commented Feb 12, 2025

Go version

go version go1.24.0 linux/amd64

Output of go env in your module/workspace:

.

What did you do?

package main

import "fmt"

func main() {
	defer foo()
	panic(123)
}

func foo() {
	for i := range iter {
		fmt.Println(i, recover()) // 0 <nil>
	}
}

func iter(yield func(int) bool) {
	yield(0)
}

What did you see happen?

0 <nil>
panic: 123

goroutine 1 [running]:
main.main()

What did you expect to see?

0 123
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 12, 2025
@zigo101
Copy link
Author

zigo101 commented Feb 12, 2025

Some like #71675, but different.

@zigo101
Copy link
Author

zigo101 commented Feb 12, 2025

BTW, I'm not sure whether or not the panic should be caught in the following code. Now it doesn't.

package main

import "fmt"

func main() {
	defer foo()
	panic(123)
}

func foo() {
	for range iter {}
}

func iter(yield func(int) bool) {
	fmt.Println(">", recover()) // > <nil>
	yield(0)
}

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 12, 2025
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 12, 2025
@dmitshur
Copy link
Contributor

CC @golang/runtime.

@mknyszek
Copy link
Contributor

In triage, we think this is almost certainly the same bug as #71675.

@mknyszek mknyszek added this to the Backlog milestone Feb 12, 2025
@zigo101
Copy link
Author

zigo101 commented Feb 13, 2025

It looks to me that in #71675, something was done incorrectly.

However, for the current issue, something was forgotten to do.

@cherrymui
Copy link
Member

While the symptoms look different, the underlying cause is probably the same -- recover matched to the wrong frame. And the fix is probably the same.

@dr2chase
Copy link
Contributor

This is not a duplicate; the fix for #71675 does not fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

7 participants