Skip to content

Commit

Permalink
server: fix gRPC gateway server close
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed May 13, 2022
1 parent ecd5c55 commit cf1cfdd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,23 @@ func (s *server) Run(rootCtx context.Context) (err error) {
case <-rootCtx.Done():
zap.L().Warn("root context is done")

zap.L().Warn("closed gRPC gateway server", zap.Error(s.gwServer.Close()))
<-gwErrc
if !s.cfg.GwDisabled {
zap.L().Warn("closed gRPC gateway server", zap.Error(s.gwServer.Close()))
<-gwErrc
}

s.gRPCServer.Stop()
zap.L().Warn("closed gRPC server")
<-gRPCErrc

case err = <-gRPCErrc:
zap.L().Warn("gRPC server failed", zap.Error(err))
zap.L().Warn("closed gRPC gateway server", zap.Error(s.gwServer.Close()))
<-gwErrc
if !s.cfg.GwDisabled {
zap.L().Warn("closed gRPC gateway server", zap.Error(s.gwServer.Close()))
<-gwErrc
}

case err = <-gwErrc:
case err = <-gwErrc: // if disabled, this will never be selected
zap.L().Warn("gRPC gateway server failed", zap.Error(err))
s.gRPCServer.Stop()
zap.L().Warn("closed gRPC server")
Expand Down

0 comments on commit cf1cfdd

Please sign in to comment.