AlexStocks commented on code in PR #3235:
URL: https://github.com/apache/dubbo-go/pull/3235#discussion_r2969086523
##########
protocol/grpc/grpc_protocol.go:
##########
@@ -38,10 +41,36 @@ const (
func init() {
extension.SetProtocol(GRPC, GetProtocol)
+
+ // register graceful shutdown callback
+ extension.RegisterGracefulShutdownCallback(GRPC, func(ctx
context.Context) error {
+ grpcProto := GetProtocol()
+ if grpcProto == nil {
+ return nil
+ }
+
+ gp, ok := grpcProto.(*GrpcProtocol)
+ if !ok {
+ return nil
+ }
+
+ gp.serverLock.Lock()
+ defer gp.serverLock.Unlock()
+
+ for _, server := range gp.serverMap {
+ server.SetAllServicesNotServing()
+ }
+
+ return nil
+ })
}
var grpcProtocol *GrpcProtocol
+var grpcServerGracefulStop = func(server *Server) {
+ server.GracefulStop()
+}
+
// GrpcProtocol is gRPC protocol
Review Comment:
## grpc_protocol.go:49 - 未使用的变量
`grpcServerGracefulStop` 定义后从未直接使用(实际调用的是 `drainServers()` 返回的 server 的
`GracefulStop()` 方法)。设计意图是方便测试时 mock,但如果测试没有用到,应删除。
**建议**: 确认是否有测试用到,如果没有则删除。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]