From 4ed149a0f03866fbf1339fe86c925f2131845b0f Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Mon, 18 Nov 2024 09:15:40 -0800 Subject: [PATCH] fix(zetaclient): lock pingRTT for writing --- cmd/zetaclientd/start.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index 46d204fa34..b9722c9213 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -231,6 +231,7 @@ func Start(_ *cobra.Command, _ []string) error { go func() { host := tssServer.GetP2PHost() pingRTT := make(map[peer.ID]int64) + pingRTTLock := sync.Mutex{} for { var wg sync.WaitGroup for _, p := range whitelistedPeers { @@ -240,6 +241,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