From 15ad28cfc8418294da316520ccc73e66affd58a7 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Sat, 19 Oct 2024 22:50:36 +0300 Subject: [PATCH] chore_: log on panic --- cmd/waku/node.go | 1 + cmd/waku/relay.go | 3 +++ cmd/waku/server/rest/filter.go | 2 ++ cmd/waku/server/rest/waku_rest.go | 2 ++ tests/utils.go | 2 ++ waku/metrics/http.go | 2 ++ waku/v2/api/history/cycle.go | 6 ++++++ waku/v2/api/history/history.go | 6 ++++++ waku/v2/protocol/filter/test_utils.go | 3 +++ 9 files changed, 27 insertions(+) diff --git a/cmd/waku/node.go b/cmd/waku/node.go index 138416bc..2f831742 100644 --- a/cmd/waku/node.go +++ b/cmd/waku/node.go @@ -356,6 +356,7 @@ func Execute(options NodeOptions) error { for _, n := range options.StaticNodes { go func(ctx context.Context, node multiaddr.Multiaddr) { + defer utils.LogOnPanic() ctx, cancel := context.WithTimeout(ctx, dialTimeout) defer cancel() err = wakuNode.DialPeerWithMultiAddress(ctx, node) diff --git a/cmd/waku/relay.go b/cmd/waku/relay.go index 26ae1de3..92373b0c 100644 --- a/cmd/waku/relay.go +++ b/cmd/waku/relay.go @@ -9,6 +9,7 @@ import ( wprotocol "github.com/waku-org/go-waku/waku/v2/protocol" "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/rendezvous" + "github.com/waku-org/go-waku/waku/v2/utils" ) func handleRelayTopics(ctx context.Context, wg *sync.WaitGroup, wakuNode *node.WakuNode, pubSubTopicMap map[string][]string) error { @@ -25,6 +26,7 @@ func handleRelayTopics(ctx context.Context, wg *sync.WaitGroup, wakuNode *node.W wg.Add(1) go func(nodeTopic string) { + defer utils.LogOnPanic() t := time.NewTicker(rendezvous.RegisterDefaultTTL) defer t.Stop() defer wg.Done() @@ -42,6 +44,7 @@ func handleRelayTopics(ctx context.Context, wg *sync.WaitGroup, wakuNode *node.W wg.Add(1) go func(nodeTopic string) { + defer utils.LogOnPanic() defer wg.Done() desiredOutDegree := wakuNode.Relay().Params().D t := time.NewTicker(7 * time.Second) diff --git a/cmd/waku/server/rest/filter.go b/cmd/waku/server/rest/filter.go index 7973cc02..42800806 100644 --- a/cmd/waku/server/rest/filter.go +++ b/cmd/waku/server/rest/filter.go @@ -14,6 +14,7 @@ import ( "github.com/waku-org/go-waku/waku/v2/protocol" "github.com/waku-org/go-waku/waku/v2/protocol/filter" "go.uber.org/zap" + "github.com/waku-org/go-waku/waku/v2/utils" ) const filterV2Subscriptions = "/filter/v2/subscriptions" @@ -32,6 +33,7 @@ type FilterService struct { // Start starts the RelayService func (s *FilterService) Start(ctx context.Context) { + defer utils.LogOnPanic() for _, sub := range s.node.FilterLightnode().Subscriptions() { s.cache.subscribe(sub.ContentFilter) diff --git a/cmd/waku/server/rest/waku_rest.go b/cmd/waku/server/rest/waku_rest.go index 6e4acb74..f9ea35bc 100644 --- a/cmd/waku/server/rest/waku_rest.go +++ b/cmd/waku/server/rest/waku_rest.go @@ -10,6 +10,7 @@ import ( "github.com/go-chi/chi/v5/middleware" "github.com/waku-org/go-waku/waku/v2/node" "go.uber.org/zap" + "github.com/waku-org/go-waku/waku/v2/utils" ) type WakuRest struct { @@ -93,6 +94,7 @@ func (r *WakuRest) Start(ctx context.Context, wg *sync.WaitGroup) { } go func() { + defer utils.LogOnPanic() _ = r.server.ListenAndServe() }() r.log.Info("server started", zap.String("addr", r.server.Addr)) diff --git a/tests/utils.go b/tests/utils.go index 82f086ae..5984d361 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -410,6 +410,7 @@ func WaitForMsg(t *testing.T, timeout time.Duration, wg *sync.WaitGroup, ch chan wg.Add(1) log := utils.Logger() go func() { + defer utils.LogOnPanic() defer wg.Done() select { case env := <-ch: @@ -425,6 +426,7 @@ func WaitForMsg(t *testing.T, timeout time.Duration, wg *sync.WaitGroup, ch chan func WaitForTimeout(t *testing.T, ctx context.Context, timeout time.Duration, wg *sync.WaitGroup, ch chan *protocol.Envelope) { wg.Add(1) go func() { + defer utils.LogOnPanic() defer wg.Done() select { case _, ok := <-ch: diff --git a/waku/metrics/http.go b/waku/metrics/http.go index 39342356..0a930316 100644 --- a/waku/metrics/http.go +++ b/waku/metrics/http.go @@ -8,6 +8,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "go.opencensus.io/plugin/ochttp" "go.uber.org/zap" + "github.com/waku-org/go-waku/waku/v2/utils" ) // Server runs and controls a HTTP pprof interface. @@ -43,6 +44,7 @@ func NewMetricsServer(address string, port int, log *zap.Logger) *Server { // Start executes the HTTP server in the background. func (p *Server) Start() { + defer utils.LogOnPanic() p.log.Info("server started ", zap.Error(p.server.ListenAndServe())) } diff --git a/waku/v2/api/history/cycle.go b/waku/v2/api/history/cycle.go index 313ee0a4..26fb09fc 100644 --- a/waku/v2/api/history/cycle.go +++ b/waku/v2/api/history/cycle.go @@ -19,6 +19,7 @@ import ( "github.com/libp2p/go-libp2p/p2p/protocol/ping" "github.com/waku-org/go-waku/waku/v2/protocol/store" "go.uber.org/zap" + "github.com/waku-org/go-waku/waku/v2/utils" ) const defaultBackoff = 10 * time.Second @@ -190,6 +191,7 @@ func (m *StorenodeCycle) getAvailableStorenodesSortedByRTT(ctx context.Context, for _, storenode := range allStorenodes { availableStorenodesWg.Add(1) go func(peerID peer.ID) { + defer utils.LogOnPanic() defer availableStorenodesWg.Done() ctx, cancel := context.WithTimeout(ctx, 4*time.Second) defer cancel() @@ -365,6 +367,8 @@ func (m *StorenodeCycle) penalizeStorenode(id peer.ID) { } func (m *StorenodeCycle) verifyStorenodeStatus(ctx context.Context) { + defer utils.LogOnPanic() + ticker := time.NewTicker(storenodeVerificationInterval) defer ticker.Stop() @@ -421,6 +425,7 @@ func (m *StorenodeCycle) WaitForAvailableStoreNode(ctx context.Context, timeout wg := sync.WaitGroup{} wg.Add(1) go func() { + defer utils.LogOnPanic() defer wg.Done() for !m.IsStorenodeAvailable(m.activeStorenode) { select { @@ -442,6 +447,7 @@ func (m *StorenodeCycle) WaitForAvailableStoreNode(ctx context.Context, timeout func waitForWaitGroup(wg *sync.WaitGroup) <-chan struct{} { ch := make(chan struct{}) go func() { + defer utils.LogOnPanic() wg.Wait() close(ch) }() diff --git a/waku/v2/api/history/history.go b/waku/v2/api/history/history.go index e95f01a5..08220c1e 100644 --- a/waku/v2/api/history/history.go +++ b/waku/v2/api/history/history.go @@ -13,6 +13,7 @@ import ( "github.com/waku-org/go-waku/waku/v2/protocol" "github.com/waku-org/go-waku/waku/v2/protocol/store" "go.uber.org/zap" + "github.com/waku-org/go-waku/waku/v2/utils" ) const maxTopicsPerRequest int = 10 @@ -81,6 +82,7 @@ func (hr *HistoryRetriever) Query( // Producer wg.Add(1) go func() { + defer utils.LogOnPanic() defer func() { logger.Debug("mailserver batch producer complete") wg.Done() @@ -117,6 +119,7 @@ func (hr *HistoryRetriever) Query( } go func() { + defer utils.LogOnPanic() workWg.Wait() workCompleteCh <- struct{}{} }() @@ -152,6 +155,7 @@ loop: semaphore <- struct{}{} go func(w work) { // Consumer + defer utils.LogOnPanic() defer func() { workWg.Done() <-semaphore @@ -227,6 +231,7 @@ func (hr *HistoryRetriever) createMessagesRequest( }) go func() { + defer utils.LogOnPanic() storeCursor, envelopesCount, err = hr.requestStoreMessages(ctx, peerID, criteria, cursor, limit, processEnvelopes) resultCh <- struct { storeCursor []byte @@ -243,6 +248,7 @@ func (hr *HistoryRetriever) createMessagesRequest( } } else { go func() { + defer utils.LogOnPanic() _, _, err = hr.requestStoreMessages(ctx, peerID, criteria, cursor, limit, false) if err != nil { logger.Error("failed to request store messages", zap.Error(err)) diff --git a/waku/v2/protocol/filter/test_utils.go b/waku/v2/protocol/filter/test_utils.go index 015cb352..7d487be4 100644 --- a/waku/v2/protocol/filter/test_utils.go +++ b/waku/v2/protocol/filter/test_utils.go @@ -189,6 +189,7 @@ func (s *FilterTestSuite) waitForMsgFromChan(msg *WakuMsg, ch chan *protocol.Env s.wg.Add(1) var msgFound = false go func() { + defer utils.LogOnPanic() defer s.wg.Done() select { case env := <-ch: @@ -233,6 +234,7 @@ func (s *FilterTestSuite) waitForMessages(msgs []WakuMsg) { s.Log.Info("Existing subscriptions ", zap.String("count", strconv.Itoa(len(subs)))) go func() { + defer utils.LogOnPanic() defer s.wg.Done() for _, sub := range subs { s.Log.Info("Looking at ", zap.String("pubSubTopic", sub.ContentFilter.PubsubTopic)) @@ -275,6 +277,7 @@ func (s *FilterTestSuite) waitForTimeout(msg *WakuMsg) { func (s *FilterTestSuite) waitForTimeoutFromChan(msg *WakuMsg, ch chan *protocol.Envelope) { s.wg.Add(1) go func() { + defer utils.LogOnPanic() defer s.wg.Done() select { case env, ok := <-ch: