Skip to content

Commit

Permalink
api: remove handleShutdown func
Browse files Browse the repository at this point in the history
This function was used for handling errors in the graceful library and
was never necessary for the v3 API.
  • Loading branch information
jzelinskie committed Sep 10, 2018
1 parent e5c2e37 commit dc6be5d
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions api/v3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ import (
"github.com/coreos/clair/database"
)

// handleShutdown handles the server shut down error.
func handleShutdown(err error) {
if err != nil {
if opErr, ok := err.(*net.OpError); !ok || (ok && opErr.Op != "accept") {
log.Fatal(err)
}
}
}

var (
promResponseDurationMilliseconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "clair_v3_api_response_duration_milliseconds",
Expand Down Expand Up @@ -178,7 +169,7 @@ func Run(Addr string, tlsConfig *tls.Config, CertFile, KeyFile string, store dat
tlsConfig.NextProtos = []string{"h2"}

apiListener = tls.NewListener(tcpMux.Match(cmux.Any()), tlsConfig)
go func() { handleShutdown(tcpMux.Serve()) }()
go func() { tcpMux.Serve() }()

grpcServer := newGrpcServer(store, tlsConfig)
gwmux := newGrpcGatewayServer(ctx, apiListener.Addr().String(), tlsConfig)
Expand All @@ -191,10 +182,10 @@ func Run(Addr string, tlsConfig *tls.Config, CertFile, KeyFile string, store dat
} else {
grpcL := tcpMux.Match(cmux.HTTP2HeaderField("content-type", "application/grpc"))
apiListener = tcpMux.Match(cmux.Any())
go func() { handleShutdown(tcpMux.Serve()) }()
go func() { tcpMux.Serve() }()

grpcServer := newGrpcServer(store, nil)
go func() { handleShutdown(grpcServer.Serve(grpcL)) }()
go func() { grpcServer.Serve(grpcL) }()

gwmux := newGrpcGatewayServer(ctx, apiListener.Addr().String(), nil)

Expand All @@ -211,7 +202,7 @@ func Run(Addr string, tlsConfig *tls.Config, CertFile, KeyFile string, store dat
}

// blocking call
handleShutdown(srv.Serve(apiListener))
srv.Serve(apiListener)
log.Info("Grpc API stopped")
}

Expand Down

0 comments on commit dc6be5d

Please sign in to comment.