]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.14] runtime: fix problem with repeated panic/recover/re-panics...
authorDan Scales <danscales@google.com>
Thu, 5 Mar 2020 20:46:04 +0000 (12:46 -0800)
committerAlexander Rakoczy <alex@golang.org>
Wed, 11 Mar 2020 14:37:29 +0000 (14:37 +0000)
commitfd85ff5ee0b0c999da59e5f56237070e1aad2df3
tree8caf8a84b4337ea0ebef63bdbab7974f9a244b55
parent8e804f19b6fe56f42696c11c494763f199bb7a0f
[release-branch.go1.14] runtime: fix problem with repeated panic/recover/re-panics and open-coded defers

In the open-code defer implementation, we add defer struct entries to the defer
chain on-the-fly at panic time to represent stack frames that contain open-coded
defers. This allows us to process non-open-coded and open-coded defers in the
correct order. Also, we need somewhere to be able to store the 'started' state of
open-coded defers. However, if a recover succeeds, defers will now be processed
inline again (unless another panic happens). Any defer entry representing a frame
with open-coded defers will become stale once we run the corresponding defers
inline and exit the associated stack frame. So, we need to remove all entries for
open-coded defers at recover time.

The current code was only removing the top-most open-coded defer from the defer
chain during recovery. However, with recursive functions that do repeated
panic-recover-repanic, multiple stale entries can accumulate on the chain. So, we
just adjust the loop to process the entire chain. Since this is at panic/recover
case, it is fine to scan through the entire chain (which should usually have few
elements in it, since most defers are open-coded).

The added test fails with a SEGV without the fix, because it tries to run a stale
open-code defer entry (and the stack has changed).

Updates #37664.
Fixes #37782.

Change-Id: I8e3da5d610b5e607411451b66881dea887f7484d
Reviewed-on: https://go-review.googlesource.com/c/go/+/222420
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
(cherry picked from commit fae87a2223e1fa959a20017742455200fe3c35f1)
Reviewed-on: https://go-review.googlesource.com/c/go/+/222818
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
src/runtime/defer_test.go
src/runtime/panic.go