mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
Skip calls to tracer when in shutdown sequence
This commit is contained in:
parent
e745ab144d
commit
330e31d83b
1 changed files with 10 additions and 4 deletions
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/tracing"
|
"github.com/ethereum/go-ethereum/core/tracing"
|
||||||
|
|
@ -35,8 +36,9 @@ import (
|
||||||
type recoverTracer struct {
|
type recoverTracer struct {
|
||||||
node *node.Node
|
node *node.Node
|
||||||
child *tracing.Hooks
|
child *tracing.Hooks
|
||||||
|
// set to true when the node is in shutdown sequence.
|
||||||
// false in tests, to prevent stack printing and misatribution of a bug
|
stopping atomic.Bool
|
||||||
|
// false in tests, to prevent stack printing and misattribution of a bug.
|
||||||
printStack bool
|
printStack bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +49,7 @@ func NewRecoverTracer(node *node.Node, child *tracing.Hooks, printStack bool) (*
|
||||||
if child == nil {
|
if child == nil {
|
||||||
return nil, fmt.Errorf("child tracer is nil")
|
return nil, fmt.Errorf("child tracer is nil")
|
||||||
}
|
}
|
||||||
rt := &recoverTracer{node, child, printStack}
|
rt := &recoverTracer{node, child, atomic.Bool{}, printStack}
|
||||||
return rt.wrapHooks()
|
return rt.wrapHooks()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +74,6 @@ func (rt *recoverTracer) wrapHooks() (*tracing.Hooks, error) {
|
||||||
methodVal := rtVal.MethodByName(field.Name)
|
methodVal := rtVal.MethodByName(field.Name)
|
||||||
// If the method exists and its type matches the hook's type, use it.
|
// If the method exists and its type matches the hook's type, use it.
|
||||||
if methodVal.IsValid() && methodVal.Type() == field.Type {
|
if methodVal.IsValid() && methodVal.Type() == field.Type {
|
||||||
fmt.Printf("Setting method %s for field %s\n", methodVal, field.Name)
|
|
||||||
newHooks.Field(i).Set(methodVal)
|
newHooks.Field(i).Set(methodVal)
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("method %s not available on recovery tracer", field.Name)
|
return nil, fmt.Errorf("method %s not available on recovery tracer", field.Name)
|
||||||
|
|
@ -89,9 +90,14 @@ func (rt *recoverTracer) wrapHooks() (*tracing.Hooks, error) {
|
||||||
// If the call panics, it logs the panic. If shutdown is true, it also initiates
|
// If the call panics, it logs the panic. If shutdown is true, it also initiates
|
||||||
// node shutdown.
|
// node shutdown.
|
||||||
func (rt *recoverTracer) safeCall(name string, shutdown bool, fn func()) {
|
func (rt *recoverTracer) safeCall(name string, shutdown bool, fn func()) {
|
||||||
|
// Skip the call if tracer has paniced before.
|
||||||
|
if rt.stopping.Load() {
|
||||||
|
return
|
||||||
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log.Error(fmt.Sprintf("panic in child tracer during %s: %v", name, r))
|
log.Error(fmt.Sprintf("panic in child tracer during %s: %v", name, r))
|
||||||
|
rt.stopping.Store(true)
|
||||||
if shutdown {
|
if shutdown {
|
||||||
if rt.printStack {
|
if rt.printStack {
|
||||||
debug.PrintStack()
|
debug.PrintStack()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue