The following code gives me an expection on the AccessSecretVersion
call, when I’m using a programm called HTTP Debugger at the same time.
public class SecretManagerService
{
private readonly SecretManagerServiceClient _client;
private readonly string _projectId;
private readonly string _secretName;
public SecretManagerService( string projectId, string secretName )
{
_client = SecretManagerServiceClient.Create();
_projectId = projectId;
_secretName = secretName;
}
public string GetSecretValue()
{
HttpClient.DefaultProxy = new WebProxy();
var secretVersionName = new SecretVersionName( _projectId, _secretName, "latest" );
var secret = _client.AccessSecretVersion( secretVersionName );
return secret.Payload.Data.ToStringUtf8();
}
public void UpdateSecretValue( string newValue )
{
var secretName = new SecretName( _projectId, _secretName );
// Set the updated value
var updatedPayload = new SecretPayload
{
Data = Google.Protobuf.ByteString.CopyFromUtf8( newValue )
};
// Update the secret
try
{
_client.AddSecretVersion( secretName, updatedPayload );
}
catch
{
Console.WriteLine( " Error updating secret" );
}
}
}
Without HTTP Debugger it runs fine.
As a workaround I can start up HTTP Debugger after this call, but that becomes anooying very quickly. I need the debugger later on in the code. So I would rather fix this problem.
The exception looks like this:
Grpc.Core.RpcException
HResult=0x80131500
Message=Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: Requesting HTTP version 2.0 with version policy RequestVersionOrHigher while unable to establish HTTP/2 connection.", DebugException="System.Net.Http.HttpRequestException: Requesting HTTP version 2.0 with version policy RequestVersionOrHigher while unable to establish HTTP/2 connection.")
Source=Grpc.Net.Client
StackTrace:
at Grpc.Net.Client.Internal.GrpcCall`2.<GetResponseHeadersCoreAsync>d__72.MoveNext()
at Grpc.Net.Client.Internal.HttpClientCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx)
at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation)
at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
at Google.Cloud.SecretManager.V1.SecretManagerService.SecretManagerServiceClient.AccessSecretVersion(AccessSecretVersionRequest request, CallOptions options)
at Google.Api.Gax.Grpc.ApiCall.GrpcCallAdapter`2.CallSync(TRequest request, CallSettings callSettings)
at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass1_0`2.<WithRetry>b__0(TRequest request, CallSettings callSettings)
at ....
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
HttpRequestException: Requesting HTTP version 2.0 with version policy RequestVersionOrHigher while unable to establish HTTP/2 connection.
I’ve already asked ChatGPT, and it indicated that I should try to use HTTP 1.1, but unfortunatly it didn’t give any usable code.
It sounds like your HTTP debugger doesn’t support HTTP/2. gRPC requires† HTTP/2, so: that’s not going to work.
†: I’m ignoring exotic transports here and referring to the standard gRPC experience