519
520
// Stop stops the service
522
>
// initiate graceful shutdown:
523
>
// 1. Fail rpc health check, this will cause client side load balancer to stop forwarding requests to this node
524
>
// 2. wait for failure detection time
525
>
// 3. stop taking new requests by returning InternalServiceError
526
>
// 4. Wait for X second
527
>
// 5. Stop everything forcefully and return
528
>
529
>
requestDrainTime := max(time.Second, s.config.ShutdownDrainDuration())
530
>
failureDetectionTime := max(0, s.config.ShutdownFailHealthCheckDuration())
531
>
532
>
s.logger.Info("ShutdownHandler: Updating gRPC health status to ShuttingDown")
533
>
s.healthServer.Shutdown()
534
>
s.membershipMonitor.SetDraining(true)
535
>
536
>
s.logger.Info("ShutdownHandler: Waiting for others to discover I am unhealthy")
537
>
time.Sleep(failureDetectionTime)
538
>
539
>
s.handler.Stop()
540
>
s.operatorHandler.Stop()
541
>
s.adminHandler.Stop()
542
>
s.versionChecker.Stop()
543
>
s.visibilityManager.Close()
544
>
545
>
s.logger.Info("ShutdownHandler: Draining traffic")
546
>
// Gracefully stop gRPC server and HTTP API server concurrently
547
>
var wg sync.WaitGroup
548
>
wg.Go(func() {
549
>
t := time.AfterFunc(requestDrainTime, func() {
550
s.logger.Info("ShutdownHandler: Drain time expired, stopping all traffic")
551
s.server.Stop()
552
})
554
>
t.Stop()
555
})
557
wg.Go(func() {
558
s.httpAPIServer.GracefulStop(requestDrainTime)
559
})
560
}
562
>
563
>
if s.metricsHandler != nil {
564
>
s.metricsHandler.Stop(s.logger)
565
>
}
566
567
>
s.logger.Info("frontend stopped")
service.go
568
}