Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trap close error on shutdown #1501

Merged
merged 1 commit into from Sep 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions server/server.go
Expand Up @@ -8,6 +8,7 @@ import (
"net/http/pprof"
"os"
"path/filepath"
"strings"

"github.com/boltdb/bolt"
containers "github.com/containerd/containerd/api/services/containers/v1"
Expand Down Expand Up @@ -129,14 +130,14 @@ func (s *Server) ServeGRPC(l net.Listener) error {
// handler. This needs to be the last service registered so that it can collect
// metrics for every other service
grpc_prometheus.Register(s.rpc)
return s.rpc.Serve(l)
return trapClosedConnErr(s.rpc.Serve(l))
}

// ServeMetrics provides a prometheus endpoint for exposing metrics
func (s *Server) ServeMetrics(l net.Listener) error {
m := http.NewServeMux()
m.Handle("/metrics", metrics.Handler())
return http.Serve(l, m)
return trapClosedConnErr(http.Serve(l, m))
}

// ServeDebug provides a debug endpoint
Expand All @@ -150,12 +151,12 @@ func (s *Server) ServeDebug(l net.Listener) error {
m.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
m.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
m.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
return http.Serve(l, m)
return trapClosedConnErr(http.Serve(l, m))
}

// Stop gracefully stops the containerd server
// Stop the containerd server canceling any open connections
func (s *Server) Stop() {
s.rpc.GracefulStop()
s.rpc.Stop()
}

func loadPlugins(config *Config) ([]*plugin.Registration, error) {
Expand Down Expand Up @@ -219,3 +220,13 @@ func interceptor(
}
return grpc_prometheus.UnaryServerInterceptor(ctx, req, info, handler)
}

func trapClosedConnErr(err error) error {
if err == nil {
return nil
}
if strings.Contains(err.Error(), "use of closed network connection") {
return nil
}
return err
}