@@ -73,9 +73,10 @@ internal void SetTrailers(RpcException fault)
7373 }
7474 }
7575
76- internal void SetTrailers < T > ( T call , Func < T , Status > getStatus , Func < T , Metadata > getMetadata )
76+ internal void SetTrailers < T > ( T ? call , Func < T , Status > getStatus , Func < T , Metadata > getMetadata )
7777 where T : class
7878 {
79+ if ( call is null ) return ;
7980 try
8081 {
8182 _trailers = getMetadata ( call ) ?? Metadata . Empty ;
@@ -88,10 +89,15 @@ internal void SetTrailers<T>(T call, Func<T, Status> getStatus, Func<T, Metadata
8889 }
8990 }
9091
91- internal ValueTask SetHeadersAsync ( Task < Metadata > headers )
92+ internal ValueTask SetHeadersAsync ( Task < Metadata > ? headers )
9293 {
94+ if ( headers is null ) return default ;
9395 var tcs = Interlocked . CompareExchange ( ref _headersTaskOrSource , headers , null ) as TaskCompletionSource < Metadata > ;
94- if ( headers . RanToCompletion ( ) )
96+ if ( tcs is null )
97+ {
98+ return new ValueTask ( headers ) ;
99+ }
100+ else if ( headers . RanToCompletion ( ) )
95101 {
96102 // headers are sync; update TCS if one
97103 tcs ? . TrySetResult ( headers . Result ) ;
@@ -103,11 +109,11 @@ internal ValueTask SetHeadersAsync(Task<Metadata> headers)
103109 return Awaited ( this , tcs , headers ) ;
104110 }
105111
106- static async ValueTask Awaited ( MetadataContext context , TaskCompletionSource < Metadata > ? tcs , Task < Metadata > headers )
112+ static async ValueTask Awaited ( MetadataContext context , TaskCompletionSource < Metadata > tcs , Task < Metadata > headers )
107113 {
108114 try
109115 {
110- tcs ? . TrySetResult ( await headers . ConfigureAwait ( false ) ) ;
116+ tcs . TrySetResult ( await headers . ConfigureAwait ( false ) ) ;
111117 }
112118 catch ( RpcException fault )
113119 {
0 commit comments