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

Fix handling of panic(nil) #960

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions v3/newrelic/internal_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"reflect"
"runtime"
"runtime/debug"
"sync"
"time"
Expand Down Expand Up @@ -445,11 +446,16 @@ func (thd *thread) End(recovered interface{}) error {

txn.finished = true

if nil != recovered {
e := txnErrorFromPanic(time.Now(), recovered)
e.Stack = getStackTrace()
thd.noticeErrorInternal(e, nil, false)
log.Println(string(debug.Stack()))
// It used to be the case that panic(nil) would cause recover() to return nil,
// which we test for here. However, that is no longer the case, hence the extra
// check at this point to stop panic(nil) from propagating here. (as of Go 1.21)
if recovered != nil {
if _, isNilPanic := recovered.(*runtime.PanicNilError); !isNilPanic {
e := txnErrorFromPanic(time.Now(), recovered)
e.Stack = getStackTrace()
thd.noticeErrorInternal(e, nil, false)
log.Println(string(debug.Stack()))
}
}

txn.markEnd(time.Now(), thd.thread)
Expand Down Expand Up @@ -542,9 +548,12 @@ func (thd *thread) End(recovered interface{}) error {
}

// Note that if a consumer uses `panic(nil)`, the panic will not
// propagate.
if nil != recovered {
panic(recovered)
// propagate. Update: well, not anymore. Go now returns an actual
// non-nil value in this case.
if recovered != nil {
if _, isNilPanic := recovered.(*runtime.PanicNilError); !isNilPanic {
panic(recovered)
}
}

return nil
Expand Down
Loading