Skip to content

Commit

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

0 comments on commit fe6d8e7

Please sign in to comment.