0
votes

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.

2

2 Answers

1
votes

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.

0
votes

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.