3

I have a grpc server and a client (in my blog project). when I run the server, It seems everything is ok, when I run the client, I face this error, and both server and client close.

rpc error: code = Unavailable desc = transport is closing

I think error is related to this piece of code:

func newPost(c proto_blog.BlogServiceClient) {
    fmt.Println("Starting to do a Unary RPC")
    req := &proto_blog.ReqNewPost{
        Title: "How can we make an gRPC server?",
        Content: "First You have to.....\nAt the end, you have to....",
        Author: "Arsham Ahora",
        Date: fmt.Sprint(time.Now()),
    }

    res, err := c.NewPost(context.Background(), req)
    if err != nil {
        log.Fatalf("Error calling greet server: %v", err)
    }
    log.Printf("Response from Greet: %v", res.Id)
}

** I noticed this error is not related to whether you have Unary or Streaming.

Arsham Arya
  • 1,461
  • 3
  • 17
  • 25

3 Answers3

2

I want to list some possible reasons cause code = Unavailable desc = transport is closing on gRPC per gRPC faq, in case of someone meets those reasons.


This error means the connection the RPC is using was closed, and there are many possible reasons, including:

  • mis-configured transport credentials, connection failed on handshaking
  • bytes disrupted, possibly by a proxy in between
  • server shutdown
  • Keepalive parameters caused connection shutdown, for example if you have configured your server to terminate connections regularly to trigger DNS lookups. If this is the case, you may want to increase your MaxConnectionAgeGrace, to allow longer RPC calls to finish.

It can be tricky to debug this because the error happens on the client side but the root cause of the connection being closed is on the server side. Turn on logging on both client and server, and see if there are any transport errors.

The default logger is controlled by environment variables. Turn everything on like this:

$ export GRPC_GO_LOG_VERBOSITY_LEVEL=99
$ export GRPC_GO_LOG_SEVERITY_LEVEL=info
zangw
  • 43,869
  • 19
  • 177
  • 214
1

I found that in server code I have a code like this before returning the response:

log.Fatalf("Error happend: %v", e)

And I changed my code like this:

if e != nil {
    log.Fatalf("Error happend: %v", e)
}

That error has not occurred but log.Fatalf() has broken my app.

For more details, it was not an error directly from the grpc part, it was because my app broke before returning any response to the gRPC client.

Arsham Arya
  • 1,461
  • 3
  • 17
  • 25
0

I think you sent wrong piece of code, anyway, As the error was said: "transport is closing" your connection is closed, You have to find where in your server you are exiting your server and handle that.