From 33ed800aae897d5b61d4fa3893fc6a0c166f63d1 Mon Sep 17 00:00:00 2001 From: pk910 Date: Thu, 24 Aug 2023 12:38:57 +0200 Subject: [PATCH] log stack trace for subroutine panics --- indexer/cacheLogic.go | 3 ++- indexer/epochStats.go | 5 +++-- indexer/synchronizer.go | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/indexer/cacheLogic.go b/indexer/cacheLogic.go index 223040a5..f27e57f8 100644 --- a/indexer/cacheLogic.go +++ b/indexer/cacheLogic.go @@ -1,6 +1,7 @@ package indexer import ( + "runtime/debug" "time" "github.com/pk910/light-beaconchain-explorer/db" @@ -11,7 +12,7 @@ import ( func (cache *indexerCache) runCacheLoop() { defer func() { if err := recover(); err != nil { - logger.WithError(err.(error)).Errorf("uncaught panic in runCacheLoop subroutine: %v", err) + logger.WithError(err.(error)).Errorf("uncaught panic in runCacheLoop subroutine: %v, stack: %v", err, string(debug.Stack())) } }() diff --git a/indexer/epochStats.go b/indexer/epochStats.go index 60d1cd8a..b22a3135 100644 --- a/indexer/epochStats.go +++ b/indexer/epochStats.go @@ -3,6 +3,7 @@ package indexer import ( "bytes" "fmt" + "runtime/debug" "strconv" "strings" "sync" @@ -167,7 +168,7 @@ func (client *IndexerClient) ensureEpochStats(epoch uint64, head []byte) error { func (epochStats *EpochStats) ensureEpochStatsLazy(client *IndexerClient, proposerRsp *rpctypes.StandardV1ProposerDutiesResponse) { defer func() { if err := recover(); err != nil { - logger.WithField("client", client.clientName).Errorf("uncaught panic in ensureEpochStats subroutine: %v", err) + logger.WithField("client", client.clientName).Errorf("uncaught panic in ensureEpochStats subroutine: %v, stack: %v", err, string(debug.Stack())) } }() epochStats.dutiesMutex.Lock() @@ -285,7 +286,7 @@ func (epochStats *EpochStats) ensureEpochStatsLazy(client *IndexerClient, propos func (epochStats *EpochStats) ensureValidatorStatsLazy(client *IndexerClient, stateRef string) { defer func() { if err := recover(); err != nil { - logger.WithField("client", client.clientName).Errorf("uncaught panic in ensureValidatorStats subroutine: %v", err) + logger.WithField("client", client.clientName).Errorf("uncaught panic in ensureValidatorStats subroutine: %v, stack: %v", err, string(debug.Stack())) } }() epochStats.loadValidatorStats(client, stateRef) diff --git a/indexer/synchronizer.go b/indexer/synchronizer.go index ef1c8cb2..89bedb7a 100644 --- a/indexer/synchronizer.go +++ b/indexer/synchronizer.go @@ -2,6 +2,7 @@ package indexer import ( "fmt" + "runtime/debug" "sync" "time" @@ -68,7 +69,7 @@ func (sync *synchronizerState) startSync(startEpoch uint64) { func (sync *synchronizerState) runSync() { defer func() { if err := recover(); err != nil { - synclogger.Errorf("uncaught panic in runSync subroutine: %v", err) + synclogger.Errorf("uncaught panic in runSync subroutine: %v, stack: %v", err, string(debug.Stack())) } }()