Skip to content

when to shutdown channel? #10732

@sj602

Description

@sj602

When is the proper time to close the channel?
I want to keep a persistent connection to a gRPC server so I don't want to close it actually.
However, I got an exception like this intermittently as a gRPC client. And what is weird is that the whole business logic worked properly.

*~*~*~ Channel ManagedChannelImpl{logId=8, target=SOME_TARGET_ADDRESS_AND_PORT} was not shutdown properly!!! ~*~*~*
    Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.

After a few researches, I found the reason for the exception which is that the reference to the channel is going to be removed by GC but is not properly shutdown. And even though it's an exception, it is for the warning purpose to close the channel explicitly.

  • What really triggers grpc-java to throw the exception? Is it like the previous channel is closed because of some random causes and the new channel is created internally, so that the previous channel becomes the target for GC?
  • What if I don't want to close the channel and want to use it forever as long as the process is alive?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions