Skip to content

Commit

Permalink
log stack trace for subroutine panics
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 24, 2023
1 parent ce07cfd commit 33ed800
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion indexer/cacheLogic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package indexer

import (
"runtime/debug"
"time"

"github.com/pk910/light-beaconchain-explorer/db"
Expand All @@ -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()))
}
}()

Expand Down
5 changes: 3 additions & 2 deletions indexer/epochStats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indexer
import (
"bytes"
"fmt"
"runtime/debug"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion indexer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package indexer

import (
"fmt"
"runtime/debug"
"sync"
"time"

Expand Down Expand Up @@ -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()))
}
}()

Expand Down

0 comments on commit 33ed800

Please sign in to comment.