From 88b744960bfd3f4e93afce27bfae23fa93f1ea95 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Tue, 22 Oct 2024 16:31:43 +0100 Subject: [PATCH] fix_: add missing defer LogOnPanic --- cmd/status-cli/util.go | 2 +- healthmanager/blockchain_health_manager.go | 2 ++ metrics/metrics.go | 2 ++ protocol/encryption/publisher/publisher.go | 1 + protocol/messenger.go | 4 ++-- protocol/messenger_store_node_request_manager.go | 2 ++ rpc/client.go | 1 + services/wallet/api.go | 4 ++++ services/wallet/balance/ttl_cache.go | 6 +++++- services/wallet/common/mock/feed_subscription.go | 2 ++ waku/v1/peer.go | 2 ++ wakuv2/waku.go | 15 ++++++++++++--- 12 files changed, 36 insertions(+), 7 deletions(-) diff --git a/cmd/status-cli/util.go b/cmd/status-cli/util.go index 754f49cfe..6cbc4736c 100644 --- a/cmd/status-cli/util.go +++ b/cmd/status-cli/util.go @@ -81,7 +81,7 @@ func start(p StartParams, logger *zap.SugaredLogger) (*StatusCLI, error) { } waku := backend.StatusNode().WakuV2Service() telemetryClient := telemetry.NewClient(telemetryLogger, p.TelemetryURL, backend.SelectedAccountKeyID(), p.Name, "cli", telemetry.WithPeerID(waku.PeerID().String())) - go telemetryClient.Start(context.Background()) + telemetryClient.Start(context.Background()) backend.StatusNode().WakuV2Service().SetStatusTelemetryClient(telemetryClient) } wakuAPI := wakuv2ext.NewPublicAPI(wakuService) diff --git a/healthmanager/blockchain_health_manager.go b/healthmanager/blockchain_health_manager.go index 7fcdf5d6d..54f5cc9fd 100644 --- a/healthmanager/blockchain_health_manager.go +++ b/healthmanager/blockchain_health_manager.go @@ -6,6 +6,7 @@ import ( "github.com/status-im/status-go/healthmanager/aggregator" "github.com/status-im/status-go/healthmanager/rpcstatus" + gocommon "github.com/status-im/status-go/common" ) // BlockchainFullStatus contains the full status of the blockchain, including provider statuses. @@ -72,6 +73,7 @@ func (b *BlockchainHealthManager) RegisterProvidersHealthManager(ctx context.Con statusCh := phm.Subscribe() b.wg.Add(1) go func(phm *ProvidersHealthManager, statusCh chan struct{}, providerCtx context.Context) { + defer gocommon.LogOnPanic() defer func() { phm.Unsubscribe(statusCh) b.wg.Done() diff --git a/metrics/metrics.go b/metrics/metrics.go index be04df702..fb1108b02 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -11,6 +11,7 @@ import ( prom "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/status-im/status-go/common" ) // Server runs and controls a HTTP pprof interface. @@ -55,5 +56,6 @@ func Handler(reg metrics.Registry) http.Handler { // Listen starts the HTTP server in the background. func (p *Server) Listen() { + defer common.LogOnPanic() log.Info("metrics server stopped", "err", p.server.ListenAndServe()) } diff --git a/protocol/encryption/publisher/publisher.go b/protocol/encryption/publisher/publisher.go index e7b587074..5c450cf69 100644 --- a/protocol/encryption/publisher/publisher.go +++ b/protocol/encryption/publisher/publisher.go @@ -73,6 +73,7 @@ func (p *Publisher) Stop() { } func (p *Publisher) tickerLoop() { + defer gocommon.LogOnPanic() ticker := time.NewTicker(tickerInterval * time.Second) go func() { diff --git a/protocol/messenger.go b/protocol/messenger.go index d48dca998..7d9c455f8 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -581,7 +581,7 @@ func NewMessenger( if c.wakuService != nil { c.wakuService.SetStatusTelemetryClient(telemetryClient) } - go telemetryClient.Start(ctx) + telemetryClient.Start(ctx) } messenger = &Messenger{ @@ -916,7 +916,7 @@ func (m *Messenger) Start() (*MessengerResponse, error) { for _, c := range controlledCommunities { if c.Joined() && c.HasTokenPermissions() { - go m.communitiesManager.StartMembersReevaluationLoop(c.ID(), false) + m.communitiesManager.StartMembersReevaluationLoop(c.ID(), false) } } diff --git a/protocol/messenger_store_node_request_manager.go b/protocol/messenger_store_node_request_manager.go index 84401003f..f0791b2bc 100644 --- a/protocol/messenger_store_node_request_manager.go +++ b/protocol/messenger_store_node_request_manager.go @@ -500,6 +500,8 @@ func (r *storeNodeRequest) shouldFetchNextPage(envelopesCount int) (bool, uint32 } func (r *storeNodeRequest) routine() { + defer gocommon.LogOnPanic() + r.manager.logger.Info("starting store node request", zap.Any("requestID", r.requestID), zap.String("pubsubTopic", r.pubsubTopic), diff --git a/rpc/client.go b/rpc/client.go index b492a84b4..77a44e79b 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -188,6 +188,7 @@ func (c *Client) Stop() { } func (c *Client) monitorHealth(ctx context.Context, statusCh chan struct{}) { + defer appCommon.LogOnPanic() sendFullStatusEventFunc := func() { blockchainStatus := c.healthMgr.GetFullStatus() encodedMessage, err := json.Marshal(blockchainStatus) diff --git a/services/wallet/api.go b/services/wallet/api.go index 934023873..3ffb44e77 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -42,6 +42,7 @@ import ( "github.com/status-im/status-go/services/wallet/walletconnect" "github.com/status-im/status-go/signal" "github.com/status-im/status-go/transactions" + common2 "github.com/status-im/status-go/common" ) func NewAPI(s *Service) *API { @@ -779,6 +780,7 @@ func (api *API) BuildTransactionsFromRoute(ctx context.Context, buildInputParams log.Debug("[WalletAPI::BuildTransactionsFromRoute] builds transactions from the generated best route", "uuid", buildInputParams.Uuid) go func() { + defer common2.LogOnPanic() api.router.StopSuggestedRoutesAsyncCalculation() var err error @@ -841,6 +843,7 @@ func (api *API) ProceedWithTransactionsSignatures(ctx context.Context, signature func (api *API) SendRouterTransactionsWithSignatures(ctx context.Context, sendInputParams *requests.RouterSendTransactionsParams) { log.Debug("[WalletAPI:: SendRouterTransactionsWithSignatures] sign with signatures and send") go func() { + defer common2.LogOnPanic() var ( err error @@ -927,6 +930,7 @@ func (api *API) SendRouterTransactionsWithSignatures(ctx context.Context, sendIn chainIDs = append(chainIDs, tx.FromChain) addresses = append(addresses, common.Address(tx.FromAddress)) go func(chainId uint64, txHash common.Hash) { + defer common2.LogOnPanic() err = api.s.transactionManager.WatchTransaction(context.Background(), chainId, txHash) if err != nil { return diff --git a/services/wallet/balance/ttl_cache.go b/services/wallet/balance/ttl_cache.go index a438658bb..596bec390 100644 --- a/services/wallet/balance/ttl_cache.go +++ b/services/wallet/balance/ttl_cache.go @@ -8,6 +8,7 @@ import ( "github.com/jellydator/ttlcache/v3" "github.com/ethereum/go-ethereum/log" + "github.com/status-im/status-go/common" ) var ( @@ -56,7 +57,10 @@ func (c *ttlCache[K, V]) init() { c.cache.OnEviction(func(ctx context.Context, reason ttlcache.EvictionReason, item *ttlcache.Item[K, V]) { log.Debug("Evicting item from balance/nonce cache", "reason", reason, "key", item.Key, "value", item.Value) }) - go c.cache.Start() // starts automatic expired item deletion + go func() { // starts automatic expired item deletion + defer common.LogOnPanic() + c.cache.Start() + }() } //nolint:golint,unused // linter does not detect using it via reflect diff --git a/services/wallet/common/mock/feed_subscription.go b/services/wallet/common/mock/feed_subscription.go index b508ded5f..fe6a9be39 100644 --- a/services/wallet/common/mock/feed_subscription.go +++ b/services/wallet/common/mock/feed_subscription.go @@ -5,6 +5,7 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/status-im/status-go/services/wallet/walletevent" + "github.com/status-im/status-go/common" ) type FeedSubscription struct { @@ -20,6 +21,7 @@ func NewFeedSubscription(feed *event.Feed) *FeedSubscription { subscription := feed.Subscribe(events) go func() { + defer common.LogOnPanic() <-done subscription.Unsubscribe() close(events) diff --git a/waku/v1/peer.go b/waku/v1/peer.go index 196d0e0ac..9882e62d7 100644 --- a/waku/v1/peer.go +++ b/waku/v1/peer.go @@ -481,6 +481,8 @@ func (p *Peer) handshake() error { // update executes periodic operations on the peer, including message transmission // and expiration. func (p *Peer) update() { + defer gocommon.LogOnPanic() + // Start the tickers for the updates expire := time.NewTicker(common.ExpirationCycle) transmit := time.NewTicker(common.TransmissionCycle) diff --git a/wakuv2/waku.go b/wakuv2/waku.go index 43c0626bc..d1f6b7279 100644 --- a/wakuv2/waku.go +++ b/wakuv2/waku.go @@ -196,7 +196,10 @@ func (w *Waku) SetStatusTelemetryClient(client ITelemetryClient) { func newTTLCache() *ttlcache.Cache[gethcommon.Hash, *common.ReceivedMessage] { cache := ttlcache.New[gethcommon.Hash, *common.ReceivedMessage](ttlcache.WithTTL[gethcommon.Hash, *common.ReceivedMessage](cacheTTL)) - go cache.Start() + go func() { + defer gocommon.LogOnPanic() + cache.Start() + }() return cache } @@ -1219,7 +1222,10 @@ func (w *Waku) Start() error { w.wg.Add(1) go w.broadcast() - go w.sendQueue.Start(w.ctx) + go func() { + defer gocommon.LogOnPanic() + w.sendQueue.Start(w.ctx) + }() err = w.startMessageSender() if err != nil { @@ -1718,7 +1724,10 @@ func (w *Waku) ConnectionChanged(state connection.State) { isOnline := !state.Offline if w.cfg.LightClient { //TODO: Update this as per https://github.com/waku-org/go-waku/issues/1114 - go w.filterManager.OnConnectionStatusChange("", isOnline) + go func() { + defer gocommon.LogOnPanic() + w.filterManager.OnConnectionStatusChange("", isOnline) + }() w.handleNetworkChangeFromApp(state) } else { // for lightClient state update and onlineChange is handled in filterManager.