DEV Community

Discussion on: gRPC quick start in Go

Collapse
 
ernsheong profile image
Jonathan ES Lin • Edited

What's interesting to me is that when I create the GRPC client in another package (outside main) and try to use it elsewhere... the GRPC calls fails with:

rpc error: code = Canceled desc = grpc: the client connection is closing

Any thoughts on this peculiarity?

Collapse
 
dannypsnl profile image
林子篆

Not sure what happened on your computer, could you provide a sample for reproducing?

Collapse
 
ernsheong profile image
Jonathan ES Lin

Thanks for the reply. I figured it out. Gotta be careful with defer conn.Close() if calling outside main function... After function ends it will close the connection and the client cannot be used anymore.

Thread Thread
 
dannypsnl profile image
林子篆

Good to hear that; yes, better to using context if you want to manage the lifecycle. It provides a not bad abstraction for stopping a goroutine.