Skip to content

Commit 6cc34ee

Browse files
Update Grpc dependency to 2.43.0 (#1576)
Co-authored-by: James Newton-King <[email protected]>
1 parent 257da89 commit 6cc34ee

29 files changed

+107
-69
lines changed

build/dependencies.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<BenchmarkDotNetPackageVersion>0.12.1</BenchmarkDotNetPackageVersion>
44
<GoogleProtobufPackageVersion>3.18.1</GoogleProtobufPackageVersion>
55
<GrpcDotNetPackageVersion>2.42.0-pre1</GrpcDotNetPackageVersion> <!-- Used by example projects -->
6-
<GrpcPackageVersion>2.42.0</GrpcPackageVersion>
6+
<GrpcPackageVersion>2.43.0</GrpcPackageVersion>
77
<MicrosoftAspNetCoreAppPackageVersion>6.0.0</MicrosoftAspNetCoreAppPackageVersion>
88
<MicrosoftAspNetCoreApp5PackageVersion>5.0.3</MicrosoftAspNetCoreApp5PackageVersion>
99
<MicrosoftAspNetCoreApp31PackageVersion>3.1.3</MicrosoftAspNetCoreApp31PackageVersion>

perf/Grpc.AspNetCore.Microbenchmarks/Server/UnaryServerCallHandlerBenchmarkBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void GlobalSetup()
7171

7272
var marshaller = CreateMarshaller();
7373

74-
var method = new Method<ChatMessage, ChatMessage>(MethodType.Unary, typeof(TestService).FullName, nameof(TestService.SayHello), marshaller, marshaller);
74+
var method = new Method<ChatMessage, ChatMessage>(MethodType.Unary, typeof(TestService).FullName!, nameof(TestService.SayHello), marshaller, marshaller);
7575
var result = Task.FromResult(message);
7676
_callHandler = new UnaryServerCallHandler<TestService, ChatMessage, ChatMessage>(
7777
new UnaryServerMethodInvoker<TestService, ChatMessage, ChatMessage>(

src/Grpc.AspNetCore.Server/Internal/GrpcProtocolHelpers.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ public static AuthContext CreateAuthContext(X509Certificate2 clientCertificate)
204204
}
205205
}
206206

207-
return new AuthContext(peerIdentityPropertyName, properties);
207+
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
208+
return new AuthContext(peerIdentityPropertyName!, properties);
208209

209210
static void AddProperty(Dictionary<string, List<AuthProperty>> properties, string name, string value)
210211
{

src/Grpc.AspNetCore.Server/Internal/HttpContextServerCallContext.cs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace Grpc.AspNetCore.Server.Internal
2929
{
3030
internal sealed partial class HttpContextServerCallContext : ServerCallContext, IServerCallContextFeature
3131
{
32-
private static readonly AuthContext UnauthenticatedContext = new AuthContext(null, new Dictionary<string, List<AuthProperty>>());
32+
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
33+
private static readonly AuthContext UnauthenticatedContext = new AuthContext(null!, new Dictionary<string, List<AuthProperty>>());
3334
private string? _peer;
3435
private Metadata? _requestHeaders;
3536
private Metadata? _responseTrailers;
@@ -72,7 +73,7 @@ internal DefaultDeserializationContext DeserializationContext
7273

7374
protected override string HostCore => HttpContext.Request.Host.Value;
7475

75-
protected override string? PeerCore
76+
protected override string PeerCore
7677
{
7778
get
7879
{
@@ -96,6 +97,10 @@ protected override string? PeerCore
9697
break;
9798
}
9899
}
100+
else
101+
{
102+
_peer = "unknown"; // Match Grpc.Core
103+
}
99104
}
100105

101106
return _peer;
@@ -295,7 +300,10 @@ private void LogCallEnd()
295300
GrpcEventSource.Log.CallStop();
296301
}
297302

303+
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
304+
#pragma warning disable CS8764 // Nullability of return type doesn't match overridden member (possibly because of nullability attributes).
298305
protected override WriteOptions? WriteOptionsCore { get; set; }
306+
#pragma warning restore CS8764 // Nullability of return type doesn't match overridden member (possibly because of nullability attributes).
299307

300308
protected override AuthContext AuthContextCore
301309
{
@@ -324,7 +332,7 @@ protected override AuthContext AuthContextCore
324332

325333
internal bool HasBufferedMessage { get; set; }
326334

327-
protected override ContextPropagationToken CreatePropagationTokenCore(ContextPropagationOptions options)
335+
protected override ContextPropagationToken CreatePropagationTokenCore(ContextPropagationOptions? options)
328336
{
329337
// TODO(JunTaoLuo, JamesNK): Currently blocked on ContextPropagationToken implementation in Grpc.Core.Api
330338
// https://github.com/grpc/grpc-dotnet/issues/40
@@ -333,30 +341,32 @@ protected override ContextPropagationToken CreatePropagationTokenCore(ContextPro
333341

334342
protected override Task WriteResponseHeadersAsyncCore(Metadata responseHeaders)
335343
{
344+
if (responseHeaders == null)
345+
{
346+
throw new ArgumentNullException(nameof(responseHeaders));
347+
}
348+
336349
// Headers can only be written once. Throw on subsequent call to write response header instead of silent no-op.
337350
if (HttpContext.Response.HasStarted)
338351
{
339352
throw new InvalidOperationException("Response headers can only be sent once per call.");
340353
}
341354

342-
if (responseHeaders != null)
355+
foreach (var entry in responseHeaders)
343356
{
344-
foreach (var entry in responseHeaders)
357+
if (entry.Key == GrpcProtocolConstants.CompressionRequestAlgorithmHeader)
345358
{
346-
if (entry.Key == GrpcProtocolConstants.CompressionRequestAlgorithmHeader)
347-
{
348-
// grpc-internal-encoding-request is used in the server to set message compression
349-
// on a per-call bassis.
350-
// 'grpc-encoding' is sent even if WriteOptions.Flags = NoCompress. In that situation
351-
// individual messages will not be written with compression.
352-
ResponseGrpcEncoding = entry.Value;
353-
HttpContext.Response.Headers[GrpcProtocolConstants.MessageEncodingHeader] = ResponseGrpcEncoding;
354-
}
355-
else
356-
{
357-
var encodedValue = entry.IsBinary ? Convert.ToBase64String(entry.ValueBytes) : entry.Value;
358-
HttpContext.Response.Headers.Append(entry.Key, encodedValue);
359-
}
359+
// grpc-internal-encoding-request is used in the server to set message compression
360+
// on a per-call bassis.
361+
// 'grpc-encoding' is sent even if WriteOptions.Flags = NoCompress. In that situation
362+
// individual messages will not be written with compression.
363+
ResponseGrpcEncoding = entry.Value;
364+
HttpContext.Response.Headers[GrpcProtocolConstants.MessageEncodingHeader] = ResponseGrpcEncoding;
365+
}
366+
else
367+
{
368+
var encodedValue = entry.IsBinary ? Convert.ToBase64String(entry.ValueBytes) : entry.Value;
369+
HttpContext.Response.Headers.Append(entry.Key, encodedValue);
360370
}
361371
}
362372

src/Grpc.Net.Client/GrpcChannel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ private void ResolveCredentials(GrpcChannelOptions channelOptions, out bool isSe
177177
if (channelOptions.Credentials != null)
178178
{
179179
var configurator = new DefaultChannelCredentialsConfigurator();
180-
channelOptions.Credentials.InternalPopulateConfiguration(configurator, null);
180+
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
181+
channelOptions.Credentials.InternalPopulateConfiguration(configurator, null!);
181182

182183
isSecure = configurator.IsSecure ?? false;
183184
callCredentials = configurator.CallCredentials;

src/Grpc.Net.Client/Internal/ClientStreamWriterBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ protected ClientStreamWriterBase(ILogger logger)
3636
WriteLock = new object();
3737
}
3838

39+
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
40+
#pragma warning disable CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
3941
public abstract WriteOptions? WriteOptions { get; set; }
42+
#pragma warning restore CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
4043

4144
public abstract Task CompleteAsync();
4245

src/Grpc.Net.Client/Internal/DefaultChannelCredentialsConfigurator.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ internal class DefaultChannelCredentialsConfigurator : ChannelCredentialsConfigu
2727

2828
public override void SetCompositeCredentials(object state, ChannelCredentials channelCredentials, CallCredentials callCredentials)
2929
{
30-
channelCredentials.InternalPopulateConfiguration(this, null);
30+
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
31+
channelCredentials.InternalPopulateConfiguration(this, null!);
3132

3233
if (callCredentials != null)
3334
{
@@ -42,7 +43,7 @@ public override void SetCompositeCredentials(object state, ChannelCredentials ch
4243

4344
public override void SetInsecureCredentials(object state) => IsSecure = false;
4445

45-
public override void SetSslCredentials(object state, string rootCertificates, KeyCertificatePair keyCertificatePair, VerifyPeerCallback verifyPeerCallback)
46+
public override void SetSslCredentials(object state, string? rootCertificates, KeyCertificatePair? keyCertificatePair, VerifyPeerCallback? verifyPeerCallback)
4647
{
4748
if (!string.IsNullOrEmpty(rootCertificates) ||
4849
keyCertificatePair != null ||

src/Grpc.Net.Client/Internal/GrpcProtocolHelpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ internal static async Task ReadCredentialMetadata(
262262
IMethod method,
263263
CallCredentials credentials)
264264
{
265-
credentials.InternalPopulateConfiguration(configurator, null);
265+
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
266+
credentials.InternalPopulateConfiguration(configurator, null!);
266267

267268
if (configurator.Interceptor != null)
268269
{
@@ -409,7 +410,7 @@ public static bool TryGetStatusCore(HttpHeaders headers, [NotNullWhen(true)] out
409410
grpcMessage = Uri.UnescapeDataString(grpcMessage);
410411
}
411412

412-
status = new Status((StatusCode)statusValue, grpcMessage);
413+
status = new Status((StatusCode)statusValue, grpcMessage ?? string.Empty);
413414
return true;
414415
}
415416

src/Grpc.Net.Client/Internal/HttpClientCallInvoker.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public HttpClientCallInvoker(GrpcChannel channel)
3737
/// Invokes a client streaming call asynchronously.
3838
/// In client streaming scenario, client sends a stream of requests and server responds with a single response.
3939
/// </summary>
40-
public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
40+
public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options)
4141
{
4242
var call = CreateRootGrpcCall<TRequest, TResponse>(Channel, method, options);
4343
call.StartClientStreaming();
4444

4545
return new AsyncClientStreamingCall<TRequest, TResponse>(
46-
requestStream: call.ClientStreamWriter,
46+
requestStream: call.ClientStreamWriter!,
4747
responseAsync: call.GetResponseAsync(),
4848
responseHeadersAsync: Callbacks<TRequest, TResponse>.GetResponseHeadersAsync,
4949
getStatusFunc: Callbacks<TRequest, TResponse>.GetStatus,
@@ -57,14 +57,14 @@ public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreami
5757
/// In duplex streaming scenario, client sends a stream of requests and server responds with a stream of responses.
5858
/// The response stream is completely independent and both side can be sending messages at the same time.
5959
/// </summary>
60-
public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
60+
public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options)
6161
{
6262
var call = CreateRootGrpcCall<TRequest, TResponse>(Channel, method, options);
6363
call.StartDuplexStreaming();
6464

6565
return new AsyncDuplexStreamingCall<TRequest, TResponse>(
66-
requestStream: call.ClientStreamWriter,
67-
responseStream: call.ClientStreamReader,
66+
requestStream: call.ClientStreamWriter!,
67+
responseStream: call.ClientStreamReader!,
6868
responseHeadersAsync: Callbacks<TRequest, TResponse>.GetResponseHeadersAsync,
6969
getStatusFunc: Callbacks<TRequest, TResponse>.GetStatus,
7070
getTrailersFunc: Callbacks<TRequest, TResponse>.GetTrailers,
@@ -76,13 +76,13 @@ public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreami
7676
/// Invokes a server streaming call asynchronously.
7777
/// In server streaming scenario, client sends on request and server responds with a stream of responses.
7878
/// </summary>
79-
public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
79+
public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options, TRequest request)
8080
{
8181
var call = CreateRootGrpcCall<TRequest, TResponse>(Channel, method, options);
8282
call.StartServerStreaming(request);
8383

8484
return new AsyncServerStreamingCall<TResponse>(
85-
responseStream: call.ClientStreamReader,
85+
responseStream: call.ClientStreamReader!,
8686
responseHeadersAsync: Callbacks<TRequest, TResponse>.GetResponseHeadersAsync,
8787
getStatusFunc: Callbacks<TRequest, TResponse>.GetStatus,
8888
getTrailersFunc: Callbacks<TRequest, TResponse>.GetTrailers,
@@ -93,7 +93,7 @@ public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRe
9393
/// <summary>
9494
/// Invokes a simple remote call asynchronously.
9595
/// </summary>
96-
public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
96+
public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options, TRequest request)
9797
{
9898
var call = CreateRootGrpcCall<TRequest, TResponse>(Channel, method, options);
9999
call.StartUnary(request);
@@ -110,7 +110,7 @@ public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Me
110110
/// <summary>
111111
/// Invokes a simple remote call in a blocking fashion.
112112
/// </summary>
113-
public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
113+
public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options, TRequest request)
114114
{
115115
var call = AsyncUnaryCall(method, host, options, request);
116116
return call.ResponseAsync.GetAwaiter().GetResult();

src/Grpc.Net.Client/Internal/Retry/StatusGrpcCall.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ private sealed class StatusClientStreamWriter : IClientStreamWriter<TRequest>
9494
{
9595
private readonly Status _status;
9696

97+
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
98+
#pragma warning disable CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
9799
public WriteOptions? WriteOptions { get; set; }
100+
#pragma warning restore CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
98101

99102
public StatusClientStreamWriter(Status status)
100103
{

0 commit comments

Comments
 (0)