grpc-go: calling Server.GracefulStop causes "accept tcp host:port: use of closed network connection"

When starting and stopping the gRPC server gracefully using Server.GracefulStop I noticed the following error.

accept tcp host:port: use of closed network connection

This error does not occur when only calling Server.Stop.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 11
  • Comments: 15 (3 by maintainers)

Most upvoted comments

I do not stop the server before starting it. Why should somebody do that actually? Anyway, the “problem” here is that you stop a server and you get an error no matter what you do. I figured out that it is because of the Close method of https://golang.org/pkg/net/#Listener. Documentation also states this.

// Any blocked Accept operations will be unblocked and return errors.

So my explanation would be that the gRPC server listens and thus calls net.Listener.Accept, which returns always the accept tcp host:port: use of closed network connection error when close is called. gRPC returns this error.

I guess you cannot do anything about this. Anyway it is really odd because users start to ignore errors like this because errors are thrown even nothing was actually wrong. In worst cases this leads to ignoring root causes of serious problems.

In my former comment I pointed out that the error comes from https://golang.org/pkg/net/#Listener, which documentation puts this:

// Any blocked Accept operations will be unblocked and return errors.

So why should something produce an error when I request it to stop any action? Errors indicate faulty behaviour. When I make proper use of the net.Listener API there shouldn’t be an error produced. I want to make the listener stop listening. I am not providing wrong arguments. I make proper use of its API. So this is why I think there should be a discussion with the go developers. Otherwise the current behaviour will only lead to people hiding errors, which in the worst case scenario will cause serious harm.