Can grpc connection be closed and re established without restarting the app in golang?

28 views
Skip to first unread message

Arpitha Rao

unread,
Sep 8, 2021, 11:44:48 AM9/8/21
to grpc.io

I am new to golang and grpc. I am trying to dynamically load some configurations to an app that I am currently working on. I need to learn if grpc client connection from my app to another grpc server connection in an upstream component can be closed and re established based the interrupt value(listening to a channel). I tried this, and I see panic, that says- flag redefined: host. In the flag.go file, at panic line, i see // Happens only if flags are declared with identical names.

I also tried to exit from the goroutine that established grpc connection and restart the goroutine. I see the same error.

Please let me know if closing connection and re establishing is a valid use case without having to restart the app.

Many thanks!

Easwar Swaminathan

unread,
Sep 8, 2021, 3:57:32 PM9/8/21
to grpc.io
Flag names need to be unique. This is not a restriction imposed by gRPC. This is the Go stdlib. See: https://pkg.go.dev/flag.

It is not very clear from your description what exactly you are trying to do. Closing and re-establishing a connection, although a valid operation, is not something that you should really need to do. Have you taken a look at gRPC core concepts: https://grpc.io/docs/what-is-grpc/core-concepts/. gRPC does support streaming RPCs. So you could dynamically get new configurations from a server over the same client channel.


Reply all
Reply to author
Forward
0 new messages