From fe6d8e7a08bdd6c6960ddbb25b788e21f555a40d Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Mon, 18 Nov 2024 10:54:31 -0800 Subject: [PATCH] fix(zetaclient): lock pingRTT for writing (#3181) (#3183) --- changelog.md | 6 ++++++ cmd/zetaclientd/start.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/changelog.md b/changelog.md index 331fb0e390..96b2bd05d5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # CHANGELOG +## v22.1.2 + +## Fixes + +- [3181](https://github.com/zeta-chain/node/pull/3181) - add lock around pingRTT to prevent crash + ## v22.1.1 ## Fixes diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index f86a5fa2ee..0cb4007d24 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -241,6 +241,7 @@ func start(_ *cobra.Command, _ []string) error { go func() { host := server.GetP2PHost() pingRTT := make(map[peer.ID]int64) + pingRTTLock := sync.Mutex{} for { var wg sync.WaitGroup for _, p := range whitelistedPeers { @@ -250,6 +251,8 @@ func start(_ *cobra.Command, _ []string) error { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() result := <-ping.Ping(ctx, host, p) + pingRTTLock.Lock() + defer pingRTTLock.Unlock() if result.Error != nil { masterLogger.Error().Err(result.Error).Msg("ping error") pingRTT[p] = -1 // RTT -1 indicate ping error