Skip to content

Commit e1f48e2

Browse files
committed
Handle errors when stopping the listener for gRPC server
Graceful shutdown of gRPC server
1 parent 73afdd2 commit e1f48e2

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

api/grpc_server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ func (s *GRPCServer) Start() {
4848
}
4949

5050
// Shutdown shuts down the gRPC server.
51-
func (s *GRPCServer) Shutdown(_ context.Context) {
52-
s.listener.Close()
53-
s.grpcServer.Stop()
51+
func (s *GRPCServer) Shutdown(context.Context) {
52+
if err := s.listener.Close(); err != nil && !errors.Is(err, net.ErrClosed) {
53+
s.API.Options.Logger.Err(err).Msg("failed to close listener")
54+
}
55+
s.grpcServer.GracefulStop()
5456
}
5557

5658
// createGRPCAPI creates a new gRPC API server and listener.

api/grpc_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ func Test_GRPC_Server(t *testing.T) {
3939
assert.Equal(t, config.Version, resp.GetVersion())
4040
assert.Equal(t, config.VersionInfo(), resp.GetVersionInfo())
4141

42-
grpcServer.Shutdown(context.Background())
42+
grpcServer.Shutdown(nil)
4343
}

api/http_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ func Test_HTTP_Server(t *testing.T) {
8585
assert.Equal(t, len(config.Version), len(respBodyBytes))
8686
assert.Equal(t, config.Version, string(respBodyBytes))
8787

88-
grpcServer.Shutdown(context.Background())
88+
grpcServer.Shutdown(nil)
8989
httpServer.Shutdown(context.Background())
9090
}

cmd/gatewayd_app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ func (app *GatewayDApp) stopGracefully(runCtx context.Context, sig os.Signal) {
11091109
}
11101110

11111111
if app.grpcServer != nil {
1112-
app.grpcServer.Shutdown(runCtx)
1112+
app.grpcServer.Shutdown(nil)
11131113
logger.Info().Msg("Stopped gRPC Server")
11141114
span.AddEvent("Stopped gRPC Server")
11151115
}

0 commit comments

Comments
 (0)