Skip to content

Commit

Permalink
bugtool: fix data race occurring when running commands
Browse files Browse the repository at this point in the history
A version of the classic closure with concurrency gotcha. Bind the value
of cmd in the loop to a new variable to address the issue.

Signed-off-by: Robin Hahling <robin.hahling@gw-computing.net>
  • Loading branch information
rolinh authored and gandro committed Nov 17, 2021
1 parent 1c37b81 commit 690c112
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions bugtool/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func runAll(commands []string, cmdDir string, k8sPods []string) {
continue
}

cmd := cmd // https://golang.org/doc/faq#closures_and_goroutines
err := wp.Submit(cmd, func(_ context.Context) error {
if strings.Contains(cmd, "xfrm state") {
// Output of 'ip -s xfrm state' needs additional processing to replace
Expand Down

0 comments on commit 690c112

Please sign in to comment.