grpc / grpc/grpc-dotnet

If connection is not established, the Polly retry policy i HttpMessageHandlers are not called.

Open
#2,447 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
4.5k
Forks
836
Avg merge
6d 3h
Merged PRs (30d)
7

Description

Hello,

why is not called Polly policy http message handler when connection could not be established?
I would like to retry even if connection could not be established, the service might be restarting when I'm doing the grpc call.

How can I add http message handler which will be called even during connection?

```csharp
serviceCollection
.AddGrpcClient(option =>
{
option.Address = new Uri(configuration.EndpointAddress);
option.CallOptionsActions.Add(ctx =>
ctx.CallOptions =
ctx.CallOptions
.WithDeadline(DateTime.UtcNow.Add(configuration.Deadline)))
;
})
.AddPolicyHandler(retryFunc);
```
This sample code was taken from past discussion https://github.com/grpc/grpc-dotnet/issues/686
```csharp
Func> retryFunc = (request) =>
{
return Policy.HandleResult(r => r.Headers.GetValues("grpc-status").FirstOrDefault() != "0")
.WaitAndRetryAsync(3, (input) => TimeSpan.FromSeconds(3 + input), (result, timeSpan, retryCount, context) =>
{
var grpcStatus = (StatusCode)int.Parse(result.Result.Headers.GetValues("grpc-status").FirstOrDefault() ?? "0");
Console.WriteLine($"Request failed with {grpcStatus}. Retry.");
});
};
```

Contributor guide

Open the contributing guide

Research direction

Start with the AddGrpcClient(...).AddPolicyHandler(retryFunc) pipeline shown in the issue and the prior discussion in grpc/grpc-dotnet#686. Determine whether connection-establishment failures can enter the policy handler; the issue does not specify which files or tests should change, or whether the expected result is implementation or documentation.

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
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.