2023-09-26 10:15:25 +08:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2023-09-26 17:15:27 +08:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2023-09-26 10:15:25 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GracefulStopGRPCServer(s *grpc.Server) {
|
|
|
|
if s == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ch := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(ch)
|
|
|
|
log.Debug("try to graceful stop grpc server...")
|
|
|
|
// will block until all rpc finished.
|
|
|
|
s.GracefulStop()
|
|
|
|
}()
|
|
|
|
select {
|
|
|
|
case <-ch:
|
|
|
|
case <-time.After(paramtable.Get().ProxyGrpcServerCfg.GracefulStopTimeout.GetAsDuration(time.Second)):
|
|
|
|
// took too long, manually close grpc server
|
|
|
|
log.Debug("stop grpc server...")
|
|
|
|
s.Stop()
|
|
|
|
// concurrent GracefulStop should be interrupted
|
|
|
|
<-ch
|
|
|
|
}
|
|
|
|
}
|