question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ConnectivityState.TERMINATED or change SHUTDOWN to notify after gRPC threads end.

See original GitHub issue

Is your feature request related to a problem?

We shutdown ManagedChannel asynchronously so need an asynchronous callback for determining when a channel has been completely cleaned up. This can be important for when libraries are dynamically unloaded / loaded at runtime as the order matters. Currently there is only ConnectivityState.SHUTDOWN, which means no new RPCs will be serviced, but the connection may still be operating. Notably, there is almost always a GOAWAY frame sent after this connectivity state is reached.

Describe the solution you’d like

Add ConnectivityState.TERMINATED to notify after connections have been completely closed. This would be sent after all gRPC threads have been ended.

Describe alternatives you’ve considered

ConnectivityState.SHUTDOWN could possibly be changed to report after gRPC threads have ended - it’s unclear to me what the use case is of being notified of shutdown before this has happened but there may be a use case, in which case a new enum is needed instead. That being said, because it’s only a timing issue, it would be rare to break applications by changing the behavior this way too and could be viable.

Additional context

We use gRPC in a library and have user reports of issues due to not being able to know when the gRPC library has finished shutting down.

https://github.com/open-telemetry/opentelemetry-java/issues/3521

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sanjaypujarecommented, Aug 23, 2021

ConnectivityState.SHUTDOWN could possibly be changed to report after gRPC threads have ended

That cannot be done since “shutdown” and “terminated” have clear meanings (in this context). See isShutdown and isTerminated.

So the only possibility is to add ConnectivityState.TERMINATED as you suggest. So the channel state becomes ConnectivityState.TERMINATED when isTerminated() is true for that channel. This will need changes in ConnectivityStateManager.gotoState(). Do you want to submit a PR?

Note that there is a ManagedClientTransport.Listener.transportTerminated() callback, but this is per subchannel and a channel has one or more subchannels.

0reactions
ejona86commented, Aug 26, 2021

Okay. Sorry, but that does seem for the best in your specific case.

For posterity: it seems fairly easy to add a calback-based API for termination state. And it could be okay if you want to directExecutor() with it, but most applicable cases of directExecutor() just trigger a notification in another thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add ConnectivityState.TERMINATED or change SHUTDOWN to ...
Add ConnectivityState.TERMINATED to notify after connections have been completely closed. This would be sent after all gRPC threads have been ended. Describe ...
Read more >
OtlpGrpcExporter/Netty still active after `SdkTracerProvider ...
If we want to change the behaviour and ensure the GRPC transport has finished exporting data, OtlpGrpcSpanExporter#shutdown() relies on the ...
Read more >
ConnectivityState (grpc-all 1.51.0 API)
SHUTDOWN. This channel has started shutting down. Any new RPCs should fail immediately. Pending RPCs may continue running till the application cancels them....
Read more >
Graceful shutdown of Java GRPC server with streams
I'm trying to add graceful shutdown for my GRPC service that has some streaming APIs ... service in a TERMINATED state even though...
Read more >
Core concepts, architecture and lifecycle - gRPC
Once the client has finished writing the messages, it waits for the server to read them and return its response.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found