Skip to content

Commit e42175c

Browse files
committed
refactor: making sure that the health and metrics servers only start shutdown once jobctrl is shut down
1 parent 4180e7a commit e42175c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/kar-controllers/app/server.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,22 @@ func Run(ctx context.Context, opt *options.ServerOption) error {
7474
}
7575

7676
stopCh := make(chan struct{})
77+
// this channel is used to signal that the job controller is done
78+
jobctrlDoneCh := make(chan struct{})
7779

7880
go func() {
7981
defer close(stopCh)
8082
<-ctx.Done()
8183
}()
8284

83-
go jobctrl.Run(stopCh)
85+
go func() {
86+
jobctrl.Run(stopCh)
87+
// close the jobctrlDoneCh channel when the job controller is done
88+
close(jobctrlDoneCh)
89+
}()
90+
91+
// wait for the job controller to be done before shutting down the server
92+
<-jobctrlDoneCh
8493

8594
err = startHealthAndMetricsServers(ctx, opt)
8695
if err != nil {

0 commit comments

Comments
 (0)