Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header value duplication when double-registering? #2557

Open
ricsiLT opened this issue Oct 10, 2024 · 0 comments
Open

Header value duplication when double-registering? #2557

ricsiLT opened this issue Oct 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ricsiLT
Copy link

ricsiLT commented Oct 10, 2024

What version of gRPC and what language are you using?

Grpc.Net.ClientFactory 2.66.0
Google.Protobuf 3.25.2

What operating system (Linux, Windows,...) and version?

Windows

What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info)

.net8

What did you do?

If possible, provide a recipe for reproducing the error. Try being specific and include code snippets if helpful.

We have the following IServiceCollection extension methods:

AddWrappedStreamGrpcClient(IServiceCollection serviceCollection) {
    serviceCollection
        .AddGrpcClient<MyService.MyClient>()
        .AddCustomCallCredentials();
    serviceCollection.AddTransient<IStreamRpcWrapper, StreamRpcWrapper>
}
----
AddWrappedQeuryGrpcClient(IServiceCollection serviceCollection) {
    serviceCollection
        .AddGrpcClient<MyService.MyClient>()
        .AddCustomCallCredentials();
    serviceCollection.AddTransient<IQueryRpcWrapper, QueryRpcWrapper>();
}

Where both wrappers take MyService.MyClient into their constructor.

What did you expect to see?

When doing the following:

builder.Services.AddWrappedStreamGrpcClient().AddWrappedQeuryGrpcClient()

I'd expect both of my wrapper classes to get separate instances of grpc client, as far as the classes are concerned.

What did you see instead?

Due to double-instantiation, request header is somehow doubled. And not two headers, but two values in a single header:

Authorization: Bearer ey<...>, Bearer ey<...>

Anything else we should know about your project / environment?

.AddCustomCallCredentials() doesn't do anything outlandish, and I even tried to prevent it from adding metadata again:

        foreach (var entry in metadata)
        {
            if (entry.Key == "Authorization") return;
        }

        var token = (await tokenHelper.GetTokens()).AccessToken.Value;
        if (string.IsNullOrEmpty(token))
        {
            throw new ArgumentNullException(token);
        }

        metadata.Add("Authorization", $"Bearer {token}");
    }

I suppose I could redo the interface into:

AddSystemPrerequisites(); // register client + auth here
AddWrappedStreamGrpcClient();
AddWrappedQeuryGrpcClient();

but I was wondering if this behavior is intented.

@ricsiLT ricsiLT added the bug Something isn't working label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant