Skip to content

Commit

Permalink
fix(zetaclient): lock pingRTT for writing
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Nov 18, 2024
1 parent 6e03cc6 commit 4ed149a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 4ed149a

Please sign in to comment.