Skip to content

Commit 9bc18f1

Browse files
authored
Fix watchdog (#93)
1 parent 3480e26 commit 9bc18f1

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

internal/manifest.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"io"
77
"os"
88
"strings"
9-
"sync"
109
"text/template"
1110
"time"
1211

@@ -100,7 +99,6 @@ type ServiceWatchdog interface {
10099
}
101100

102101
func RunWatchdog(manifest *Manifest) error {
103-
var wg sync.WaitGroup
104102
watchdogErr := make(chan error, len(manifest.Services()))
105103

106104
output, err := manifest.out.LogOutput("watchdog")
@@ -110,23 +108,17 @@ func RunWatchdog(manifest *Manifest) error {
110108

111109
for _, s := range manifest.Services() {
112110
if watchdogFn, ok := s.component.(ServiceWatchdog); ok {
113-
wg.Add(1)
114-
115111
go func() {
116-
defer wg.Done()
117112
if err := watchdogFn.Watchdog(output, s, context.Background()); err != nil {
118113
watchdogErr <- fmt.Errorf("service %s watchdog failed: %w", s.Name, err)
119114
}
120115
}()
121116
}
122117
}
123-
wg.Wait()
124118

125-
close(watchdogErr)
126-
for err := range watchdogErr {
127-
if err != nil {
128-
return err
129-
}
119+
// If any of the watchdogs fail, we return the error
120+
if err := <-watchdogErr; err != nil {
121+
return fmt.Errorf("failed to run watchdog: %w", err)
130122
}
131123
return nil
132124
}

0 commit comments

Comments
 (0)