Skip to content

Commit 96ffc09

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

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: cmd/kar-controllers/app/server.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,22 @@ func Run(ctx context.Context, opt *options.ServerOption) error {
7171
}
7272

7373
stopCh := make(chan struct{})
74+
// this channel is used to signal that the job controller is done
75+
jobctrlDoneCh := make(chan struct{})
7476

7577
go func() {
7678
defer close(stopCh)
7779
<-ctx.Done()
7880
}()
7981

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

8291
err = startHealthAndMetricsServers(ctx, opt)
8392
if err != nil {

0 commit comments

Comments
 (0)