mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-12 20:50:05 +00:00
Add panic handler (#3296)
This commit is contained in:
parent
3b422cb9c6
commit
a852d610e2
@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
@ -85,6 +86,13 @@ func (r *RegularSync) subscribe(topic string, validate validator, handle subHand
|
||||
// Pipeline decodes the incoming subscription data, runs the validation, and handles the
|
||||
// message.
|
||||
pipeline := func(data []byte) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.WithField("error", r).Error("Panic occurred")
|
||||
debug.PrintStack()
|
||||
}
|
||||
}()
|
||||
|
||||
if data == nil {
|
||||
log.Warn("Received nil message on pubsub")
|
||||
return
|
||||
|
@ -38,3 +38,26 @@ func TestSubscribe_ReceivesValidMessage(t *testing.T) {
|
||||
t.Fatal("Did not receive PubSub in 1 second")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubscribe_HandlesPanic(t *testing.T) {
|
||||
p2p := p2ptest.NewTestP2P(t)
|
||||
r := RegularSync{
|
||||
ctx: context.Background(),
|
||||
p2p: p2p,
|
||||
}
|
||||
|
||||
topic := "/eth2/voluntary_exit"
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
|
||||
r.subscribe(topic, noopValidator, func(_ context.Context, msg proto.Message) error {
|
||||
defer wg.Done()
|
||||
panic("bad")
|
||||
})
|
||||
|
||||
p2p.ReceivePubSub(topic, &pb.VoluntaryExit{Epoch: 55})
|
||||
|
||||
if testutil.WaitTimeout(&wg, time.Second) {
|
||||
t.Fatal("Did not receive PubSub in 1 second")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user