Skip to content

Commit

Permalink
Fix binary search goroutine to avoid deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
schnie committed Oct 31, 2024
1 parent d6a2c1d commit a8aa1a5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions airflow/container_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"strings"
"sync"

"github.com/astronomer/astro-cli/pkg/util"

"github.com/astronomer/astro-cli/config"
"github.com/astronomer/astro-cli/pkg/fileutil"
"github.com/astronomer/astro-cli/pkg/util"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -56,7 +55,15 @@ func FindBinary(pathEnv, binaryName string, checker FileChecker) bool {
defer wg.Done()
binaryPath := filepath.Join(dir, binaryName)
if exists := checker.Exists(binaryPath); exists {
found <- binaryPath
select {
// If the channel is open, send the path in, indicating a found binary.
case found <- binaryPath:
// If another goroutine has already sent a path into the channel
// we'd be blocked. The default clause will run instead and effectively
// skip sending the path into the channel, doing nothing, but allowing the
// goroutine to complete without blocking.
default:
}
}
}(dir)
}
Expand Down

0 comments on commit a8aa1a5

Please sign in to comment.