Skip to content

Commit

Permalink
fix(cmd/auth): fix concurrency bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmalkmus committed Apr 1, 2024
1 parent 910d79c commit bf6ed64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/axiomhq/cli

go 1.21
go 1.22

require (
github.com/AlecAivazis/survey/v2 v2.3.7
Expand Down
10 changes: 7 additions & 3 deletions internal/cmd/auth/auth_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"sync"

"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -67,14 +68,14 @@ func runStatus(ctx context.Context, opts *statusOptions) error {
defer stop()

var (
cs = opts.IO.ColorScheme()
statusInfo = map[string][]string{}
cs = opts.IO.ColorScheme()
statusInfo = map[string][]string{}
statusInfoMu = new(sync.Mutex)
// We don't care about the context here. If an errors occurs, still try
// to get the status of the other deployments.
eg, _ = errgroup.WithContext(ctx)
)
for _, deploymentAlias := range deploymentAliases {
deploymentAlias := deploymentAlias
deployment, ok := opts.Config.Deployments[deploymentAlias]
if !ok {
continue
Expand All @@ -83,6 +84,9 @@ func runStatus(ctx context.Context, opts *statusOptions) error {
eg.Go(func() error {
var info string
defer func() {
statusInfoMu.Lock()
defer statusInfoMu.Unlock()

statusInfo[deploymentAlias] = append(statusInfo[deploymentAlias], info)
}()

Expand Down

0 comments on commit bf6ed64

Please sign in to comment.