No reliable way to check if a channel has been shutdown
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 836
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 7
Description
### What version of gRPC and what language are you using?
In a net8.0/net9.0 C# project, I'm using the following NuGet packages:
- Google.Protobuf/3.33.2
- Grpc.AspNetCore/2.76.0
- Grpc.Tools/2.76.0
### What operating system (Linux, Windows,...) and version?
Development is done on Windows 11. Code runs on Windows (desktop or server) or Linux (containers).
### What runtime / compiler are you using (e.g. .NET Core SDK version `dotnet --info`)
9.0.306 for development but expected to run using any 8+ (target multiple frameworks)
### What did you do?
My system includes 10+ grpc services which can be configured to use NamedPipe, UDS, or HTTP depending on the deployment implementation. I have factories that perform the setup of the services and clients based on the configuration. I followed some guidance I found online that the channels for clients should be reused because they can be expensive to create, so in my factory that creates clients I want to be able to ensure that a channel hasn't been shutdown or is in an error state before using to generate a new client, but there are no properties that allow checking that aside from the 'State' property, but that property performs some validation and throws an exception in some cases that "client-side load balancing or connectivity state tracking" isn't enabled for the channel, but there is no other way to check if a channel has been shutdown/disposed or is in an error state.
### What did you expect to see?
I expect checking `if (channel.State is ConnectivityState.Shutdown or ConnectivityState.TransientFailure)` to, at a minimum, tell me if the channel has been shutdown. Maybe there's a reason why the TransientFailure can't be reported, but it seems silly that if the channel tried to interact with the service and it failed that it can't report that and has any dependency on client-side load balancing or connectivity state tracking.
### What did you see instead?
An exception unrelated to the information that I'm trying to obtain. The exception is [thrown from here](https://github.com/grpc/grpc-dotnet/blob/2e283d98f5861e31f8956be0c68aff9a4e29cb0a/src/Grpc.Net.Client/GrpcChannel.cs#L434) which is triggered by the [State property here](https://github.com/grpc/grpc-dotnet/blob/2e283d98f5861e31f8956be0c68aff9a4e29cb0a/src/Grpc.Net.Client/GrpcChannel.cs#L760).
### Anything else we should know about your project / environment?
I don't think so.
Contributor guide
Research direction
Start in src/Grpc.Net.Client/GrpcChannel.cs at the State property and the exception path linked in the issue. Review how channel connectivity and client-side load balancing state are tracked, then determine a reliable shutdown or failure check that works with the described channel configurations. Done means callers can distinguish a disposed or failed channel without an unrelated exception, with tests covering the relevant states.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100