Skip to content

Commit

Permalink
fix: potential deadlock when executing commands in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
kernle32dll committed Apr 14, 2020
1 parent 610a4fc commit bc85f52
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/cmd/cmd_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ func (c AnyCommand) Execute() error {

func (c AnyCommand) executeParallel(paths []string) {
parallelFactor := runtime.NumCPU()
in := make(chan int, len(paths))
out := make([]chan io.ReadCloser, len(paths))
in := make(chan int, parallelFactor)
out := make([]chan *io.PipeReader, len(paths))
for i := range paths {
out[i] = make(chan io.ReadCloser, 1)
in <- i
out[i] = make(chan *io.PipeReader, 1)
}
go func() {
for i := range paths {
in <- i
}
}()

for i := 0; i < parallelFactor; i++ {
go func() {
Expand Down

0 comments on commit bc85f52

Please sign in to comment.