Skip to content

Commit

Permalink
Check if the server is properly closed before erroring out
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Dec 26, 2024
1 parent facdfc1 commit dc0bd38
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions api/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"context"
"errors"
"net"

v1 "github.com/gatewayd-io/gatewayd/api/v1"
Expand Down Expand Up @@ -41,7 +42,7 @@ func NewGRPCServer(ctx context.Context, server GRPCServer) *GRPCServer {

// Start starts the gRPC server.
func (s *GRPCServer) Start() {
if err := s.grpcServer.Serve(s.listener); err != nil {
if err := s.grpcServer.Serve(s.listener); err != nil && !errors.Is(err, net.ErrClosed) {
s.API.Options.Logger.Err(err).Msg("failed to start gRPC API")
}
}
Expand All @@ -55,7 +56,7 @@ func (s *GRPCServer) Shutdown(_ context.Context) {
// createGRPCAPI creates a new gRPC API server and listener.
func createGRPCAPI(api *API, healthchecker *HealthChecker) (*grpc.Server, net.Listener) {
listener, err := net.Listen(api.Options.GRPCNetwork, api.Options.GRPCAddress)
if err != nil {
if err != nil && !errors.Is(err, net.ErrClosed) {
api.Options.Logger.Err(err).Msg("failed to start gRPC API")
return nil, nil
}
Expand Down

0 comments on commit dc0bd38

Please sign in to comment.