Skip to content

Commit 460c341

Browse files
committed
pkg/start: exit when hostagent process exited
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 83db9de commit 460c341

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

pkg/start/start.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,26 @@ func Start(ctx context.Context, inst *store.Instance) error {
8989
return err
9090
}
9191

92-
return watchHostAgentEvents(ctx, inst.Name, haStdoutPath, haStderrPath, begin)
93-
// leave the hostagent process running
92+
watchErrCh := make(chan error)
93+
go func() {
94+
watchErrCh <- watchHostAgentEvents(ctx, inst.Name, haStdoutPath, haStderrPath, begin)
95+
close(watchErrCh)
96+
}()
97+
waitErrCh := make(chan error)
98+
go func() {
99+
waitErrCh <- haCmd.Wait()
100+
close(waitErrCh)
101+
}()
102+
103+
select {
104+
case watchErr := <-watchErrCh:
105+
// watchErr can be nil
106+
return watchErr
107+
// leave the hostagent process running
108+
case waitErr := <-waitErrCh:
109+
// waitErr should not be nil
110+
return fmt.Errorf("host agent process has exited: %w", waitErr)
111+
}
94112
}
95113

96114
func waitHostAgentStart(ctx context.Context, haPIDPath, haStderrPath string) error {

0 commit comments

Comments
 (0)