Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deploy --dry-run deadlock #120

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions cmd/deploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func main() {
args = os.Args[1:]

// --dry-run
dryRun bool
dryRunOuts chan chan []byte
dryRun bool

// --parallel
parallel bool
Expand All @@ -35,8 +34,6 @@ func main() {
switch arg {
case "--dry-run":
dryRun = true
// we want to allow parallel, but want the output to be in-order so we resynchronize output with a channel of channels (technically this also limits parallelization, but hopefully this limit is generous enough that it doesn't matter)
dryRunOuts = make(chan chan []byte, 1000)

case "--parallel":
parallel = true
Expand Down Expand Up @@ -68,6 +65,27 @@ func main() {
childMutexes := sync.Map{}
wg := sync.WaitGroup{}

var dryRunOuts chan chan []byte
if dryRun {
// we want to allow parallel, but want the output to be in-order so we resynchronize output with a channel of channels (technically this also limits parallelization, but hopefully this limit is generous enough that it doesn't matter)
dryRunOuts = make(chan chan []byte, 100000)

// we also have to start consuming that channel immediately, just in case we *do* hit that parallelization limit 🙈
wg.Add(1)
go func() {
defer wg.Done()

for dryRunOut := range dryRunOuts {
j, ok := <-dryRunOut
if !ok {
// (I think) this means we didn't output anything, so this should be all our "skips"
continue
}
fmt.Printf("%s\n", j)
}
}()
}

dec := json.NewDecoder(stdout)
for dec.More() {
var raw inputRaw
Expand Down Expand Up @@ -242,14 +260,6 @@ func main() {

if dryRun {
close(dryRunOuts)
for dryRunOut := range dryRunOuts {
j, ok := <-dryRunOut
if !ok {
// (I think) this means we didn't output anything, so this should be all our "skips"
continue
}
fmt.Printf("%s\n", j)
}
}

wg.Wait()
Expand Down