Enable lame-duck on exit, so systemctl can 'restart' collectors
This commit is contained in:
@@ -61,7 +61,22 @@ func main() {
|
|||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
log.Printf("collector: shutting down")
|
log.Printf("collector: shutting down")
|
||||||
|
|
||||||
|
// GracefulStop waits for all RPCs to finish. StreamSnapshots subscribers
|
||||||
|
// (e.g. the aggregator) hold a stream open indefinitely, so we give it a
|
||||||
|
// short window and then force-stop to avoid hanging systemctl stop/restart.
|
||||||
|
stopped := make(chan struct{})
|
||||||
|
go func() {
|
||||||
grpcServer.GracefulStop()
|
grpcServer.GracefulStop()
|
||||||
|
close(stopped)
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-stopped:
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
log.Printf("collector: graceful stop timed out, forcing stop")
|
||||||
|
grpcServer.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
close(ch)
|
close(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user