-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix panic propagation through functions that call recover
godebug has special handling for functions that call recover. godebug needs to track which goroutine is calling a given function, which it does using the github.com/jtolds/gls library. This requires being able to wrap every function into a callback that can, if needed, be called recursively after doing some clever stack manipulation. This doesn't work for functions that call recover, though, because it matters where on the stack you call recover: it has to be called directly from a deferred function. To deal with the conflicting requirements of (1) needing to run function bodies inside callbacks and (2) needing to _not_ run recover calls inside callbacks, godebug does something interesting. For functions that call recover, any calls to recover are replaced with a double channel communication. This modified function body can then run in a callback. Unlike the normal callbacks godebug generates, this one is run in a new goroutine. This goroutine communicates with the originl stack frame in the original goroutine. If it needs to call recover, it sends a message to the original stack frame and the original stack frame calls recover on its behalf and sends back the result over a channel. (1) and (2) are thus both accomplished. A problem with this workaround is that, because the function runs in a new goroutine, if it panics it no longer passes the panic back to its caller. It just crashes. This commit fixes that. Now, in addition to communicating recover calls, the two goroutines also communicate about panics. If the function in the new goroutine panics, it sends the panic over a channel to the original goroutine, which re-panics. This fails to preserve the stack information about the panic, but the function wrapping that caused this problem in the first place already broke that.
- Loading branch information
1 parent
cd9e20f
commit 68ded56
Showing
6 changed files
with
277 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.