Skip to content

Commit e9575bf

Browse files
committed
shut down leaseController gracefully
if leaseController is enabled and graceful shutdown is enabled as well, without this lease controller will terminate while the servers would continue to shutdown gracefully. Potentially causing a situtaion where the leases will be deleted while the existing connections are still served upto shutdown point. Signed-off-by: Imran Pochi <[email protected]>
1 parent cc87190 commit e9575bf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cmd/server/app/server.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ func (p *Proxy) Run(o *options.ProxyRunOptions, stopCh <-chan struct{}) error {
157157
return err
158158
}
159159

160+
var leaseController *leases.Controller
160161
if o.EnableLeaseController {
161-
leaseController := leases.NewController(
162+
leaseController = leases.NewController(
162163
k8sClient,
163164
o.ServerID,
164165
int32(LeaseDuration.Seconds()),
@@ -170,7 +171,6 @@ func (p *Proxy) Run(o *options.ProxyRunOptions, stopCh <-chan struct{}) error {
170171
)
171172
klog.V(1).Infoln("Starting lease acquisition and garbage collection controller.")
172173
leaseController.Run(ctx)
173-
defer leaseController.Stop()
174174
}
175175

176176
klog.V(1).Infoln("Starting admin server for debug connections.")
@@ -204,6 +204,9 @@ func (p *Proxy) Run(o *options.ProxyRunOptions, stopCh <-chan struct{}) error {
204204
if p.healthServer != nil {
205205
p.healthServer.Close()
206206
}
207+
if leaseController != nil {
208+
leaseController.Stop()
209+
}
207210
return nil
208211
}
209212

@@ -291,6 +294,12 @@ func (p *Proxy) Run(o *options.ProxyRunOptions, stopCh <-chan struct{}) error {
291294
// frontend server's force-stop is handled by its StopFunc
292295
}
293296

297+
// Stop lease controller after servers have shut down
298+
if leaseController != nil {
299+
klog.V(1).Infoln("Stopping lease controller.")
300+
leaseController.Stop()
301+
}
302+
294303
return nil
295304
}
296305

0 commit comments

Comments
 (0)