Enable lame-duck on exit, so systemctl can 'restart' collectors

This commit is contained in:
2026-03-23 22:18:05 +01:00
parent cd7f15afaf
commit 0fb84813a5

View File

@@ -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)
} }