Skip to content

Incorrect recovery from double-panic  #1126

@nevkontakte

Description

@nevkontakte

Consider the following code:

package main

import "fmt"

func main() {
	defer func() { fmt.Println(recover()) }()
	defer func() { fmt.Println(recover()) }()
	defer panic(2)
	panic(1)
}

When executed by go:

$ go run main3.go
2
<nil>

When executed by GopherJS:

$ gopherjs run main3.go
2
1

Note that in the upstream implementation the later panic overrides the earlier panic, and only one call to recover() is necessary. However, GopherJS requires a separate call to recover from each panic. While go spec isn't explicit about it, it doesn't say that there is some kind of stack of panics. Instead it only defines two states or "panicing" and "not panicing" and a successful recover() call clears the state of panicing and resumes normal execution.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions