mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 04:49:08 +08:00
6539a5ae2c
Signed-off-by: yah01 <yah2er0ne@outlook.com>
33 lines
681 B
Go
33 lines
681 B
Go
package utils
|
|
|
|
import (
|
|
"time"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"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
|
|
}
|
|
}
|