graceful shutdown refined

This commit is contained in:
kevin
2020-11-08 13:08:00 +08:00
parent 48f4154ea8
commit bd430baf52
3 changed files with 23 additions and 16 deletions

View File

@@ -68,13 +68,12 @@ func (s *rpcServer) Start(register RegisterFn) error {
register(server)
// we need to make sure all others are wrapped up
// so we do graceful stop at shutdown phase instead of wrap up phase
shutdownCalled := proc.AddShutdownListener(func() {
waitForCalled := proc.AddWrapUpListener(func() {
server.GracefulStop()
})
err = server.Serve(lis)
shutdownCalled()
defer waitForCalled()
return err
return server.Serve(lis)
}
func WithMetrics(metrics *stat.Metrics) ServerOption {

View File

@@ -16,7 +16,10 @@ import (
"google.golang.org/grpc"
)
const envPodIp = "POD_IP"
const (
allEths = "0.0.0.0"
envPodIp = "POD_IP"
)
type RpcServer struct {
server internal.Server
@@ -96,7 +99,7 @@ func figureOutListenOn(listenOn string) string {
}
host := fields[0]
if len(host) > 0 && host != "0.0.0.0" {
if len(host) > 0 && host != allEths {
return listenOn
}