Skip to content

Commit 70cff5b

Browse files
committed
Merge pull request #3802 from kalbasit/issue_3793
fix(deisctl): avoid blocking if output is empty Closes #3793. Thanks, @kalbasit !
2 parents 5765871 + e7a5479 commit 70cff5b

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

deisctl/cmd/cmd.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Usage:
8383
wg.Wait()
8484
}
8585
close(outchan)
86+
close(errchan)
8687
return nil
8788
}
8889

@@ -119,6 +120,7 @@ Usage:
119120
b.Start(targets, &wg, outchan, errchan)
120121
wg.Wait()
121122
close(outchan)
123+
close(errchan)
122124

123125
return nil
124126
}
@@ -220,6 +222,7 @@ Usage:
220222
b.Stop(targets, &wg, outchan, errchan)
221223
wg.Wait()
222224
close(outchan)
225+
close(errchan)
223226

224227
return nil
225228
}
@@ -360,6 +363,7 @@ Usage:
360363
wg.Wait()
361364

362365
close(outchan)
366+
close(errchan)
363367
return nil
364368
}
365369

@@ -423,6 +427,7 @@ Usage:
423427
b.Destroy(targets, &wg, outchan, errchan)
424428
wg.Wait()
425429
close(outchan)
430+
close(errchan)
426431

427432
return nil
428433
}
@@ -458,21 +463,27 @@ func uninstallAllServices(b backend.Backend, wg *sync.WaitGroup, outchan chan st
458463
return nil
459464
}
460465

461-
func printState(outchan chan string, errchan chan error, interval time.Duration) error {
466+
func printState(outchan chan string, errchan chan error, interval time.Duration) {
462467
for {
463468
select {
464-
case out := <-outchan:
465-
// done on closed channel
466-
if out == "" {
467-
return nil
469+
case out, ok := <-outchan:
470+
if !ok {
471+
outchan = nil
472+
}
473+
if out != "" {
474+
fmt.Println(out)
475+
}
476+
case err, ok := <-errchan:
477+
if !ok {
478+
errchan = nil
468479
}
469-
fmt.Println(out)
470-
case err := <-errchan:
471480
if err != nil {
472481
fmt.Println(err.Error())
473-
return err
474482
}
475483
}
484+
if outchan == nil && errchan == nil {
485+
break
486+
}
476487
time.Sleep(interval)
477488
}
478489
}

0 commit comments

Comments
 (0)