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

defers shouldn't re-run when repanic'ing. #3449

Open
dgryski opened this issue Feb 15, 2023 · 0 comments
Open

defers shouldn't re-run when repanic'ing. #3449

dgryski opened this issue Feb 15, 2023 · 0 comments
Labels
bug Something isn't working core

Comments

@dgryski
Copy link
Member

dgryski commented Feb 15, 2023

Looks like the panic in the defer block causes the defer to rerun, when it shouldn't.

~/go/src/github.com/dgryski/bug/repanic $ cat main.go
package main

func main() {
	var rerun int
	defer func() {
		println("defer")
		if r := recover(); r != nil {
			rerun++
			if rerun < 5 {
				panic(r)
			}
		}
	}()

	panic("boom")
}
~/go/src/github.com/dgryski/bug/repanic $ go run main.go
defer
panic: boom [recovered]
	panic: boom

goroutine 1 [running]:
main.main.func1()
	/Users/dgryski/go/src/github.com/dgryski/bug/repanic/main.go:10 +0x6d
panic({0x105ba80, 0x107a8b8})
	/Users/dgryski/go/src/go.googlesource.com/go/src/runtime/panic.go:884 +0x213
main.main()
	/Users/dgryski/go/src/github.com/dgryski/bug/repanic/main.go:15 +0x6c
exit status 2
~/go/src/github.com/dgryski/bug/repanic $ tinygo run main.go
defer
defer
defer
defer
defer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
None yet
Development

No branches or pull requests

2 participants