Skip to content

Commit

Permalink
Prevent data race while querying nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Jun 27, 2021
1 parent 025870d commit 6261b51
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions x/node/client/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,25 @@ func QueryNodes() *cobra.Command {
}

var (
wg = sync.WaitGroup{}
group = sync.WaitGroup{}
mutex = sync.Mutex{}
table = tablewriter.NewWriter(cmd.OutOrStdout())
)

table.SetHeader(header)
for i := 0; i < len(items); i++ {
wg.Add(1)
group.Add(1)
go func(i int) {
defer wg.Done()
defer group.Done()

var (
info, _ = fetchNodeInfo(items[i].RemoteURL)
item = types.NewNodeFromRaw(&items[i]).WithInfo(info)
)

mutex.Lock()
defer mutex.Unlock()

table.Append(
[]string{
item.Moniker,
Expand All @@ -231,7 +235,7 @@ func QueryNodes() *cobra.Command {
}(i)
}

wg.Wait()
group.Wait()

table.Render()
return nil
Expand Down

0 comments on commit 6261b51

Please sign in to comment.