grpc-dotnet: Error starting gRPC call. A task was canceled.

When I am doing grpc call, after some time this exception throws “Error starting gRPC call. A task was canceled.”

.net 6

Exception

{ “@timestamp”: “2022-03-30T12:37:38.5892808+04:00”, “level”: “Error”, “messageTemplate”: “Error starting gRPC call.”, “message”: “Error starting gRPC call.”, “exceptions”: [ { “Depth”: 0, “ClassName”: “System.Threading.Tasks.TaskCanceledException”, “Message”: “A task was canceled.”, “Source”: “System.Private.CoreLib”, “StackTraceString”: " at Grpc.Net.Client.Balancer.Internal.ConnectionManager.GetNextPickerAsync(CancellationToken cancellationToken)\n at Grpc.Net.Client.Balancer.Internal.ConnectionManager.PickAsync(PickContext context, Boolean waitForReady, CancellationToken cancellationToken)\n at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\n at Grpc.Net.Client.Internal.GrpcCall2.RunCall(HttpRequestMessage request, Nullable1 timeout)", “RemoteStackTraceString”: null, “RemoteStackIndex”: 0, “HResult”: -2146233029, “HelpURL”: null } ], “fields”: { “EventId”: { “Id”: 6, “Name”: “ErrorStartingCall” }, “SourceContext”: “Grpc.Net.Client.Internal.GrpcCall”, “GrpcMethodType”: “Unary”, “GrpcUri”: “/XXXXX/Get”, } }

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (6 by maintainers)

Most upvoted comments

I’ve repeated tests with 2.45.0-pre1 - everything works well. @JamesNK Thanks for fix

This is from a production service so I am unable to turn on debug logging (I’ll try to reproduce in staging/locally, but it seems to happen only under load so far). Here is the stack trace, if it is helpful:

Type: Grpc.Core.RpcException
	Source: Grpc.Net.Client.Balancer.Internal.ConnectionManager+<PickAsync>d__45, Grpc.Net.Client, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad
	Message: Status(StatusCode="Unavailable", Detail="Error connecting to subchannel.", DebugException="System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
   at Grpc.Net.Client.Balancer.Internal.ConnectionManager.UpdateState(BalancerState state)
   at Grpc.Net.Client.Balancer.Internal.ChildHandlerLoadBalancer.ChildHandlerController.UpdateState(BalancerState state)
   at Grpc.Net.Client.Balancer.PickFirstBalancer.UpdateSubchannelState(Subchannel subchannel, SubchannelState state)
   at Grpc.Net.Client.Balancer.Subchannel.RaiseStateChanged(ConnectivityState state, Status status)
   at Grpc.Net.Client.Balancer.Internal.ConnectionManager.OnSubchannelStateChange(Subchannel subchannel, ConnectivityState state, Status status)
   at Grpc.Net.Client.Balancer.Subchannel.UpdateConnectivityState(ConnectivityState state, Status status)
   at Grpc.Net.Client.Balancer.Internal.SocketConnectivitySubchannelTransport.TryConnectAsync(CancellationToken cancellationToken)")
	Trace:    at Grpc.Net.Client.Balancer.Internal.ConnectionManager.PickAsync(PickContext context, Boolean waitForReady, CancellationToken cancellationToken)
   at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)