0

With a new version of grpc a new service was introduced with a new bidirectional stream. The problem is, that when the server runs with an old grpc, the stream does not (reliably) throw an exception when writing data to the server with WriteAsync. Only MoveNext throws a RpcException. But it's a bit cumbersome to do the SetConnection when move next does NOT throw exception, with a kind of timer.
Is there a good way to find out whether the bidirectional stream can be established?

try
{
   using var streamingCall = someService.CallBidirectionalStream(cancellationToken: cancellationToken);

   // does not throw an exception, when the interface is not implemented (sometimes it does)
   // it only reliably throws rpc exception, when server not started.
   await streamingCall.RequestStream.WriteAsync(mapper.Map<SomeType>(currentData), cancellationToken)
      .ConfigureAwait(false);
   
   // should only run when connected
   using subscription = await SetConnection(streamingCall, cancellationToken)
            .ConfigureAwait(false);
            
   // only this throws exception, when not implemented.
   while (await streamingCall.ResponseStream.MoveNext(cancellationToken)
       .ConfigureAwait(false))
   {               
       var response = streamingCall.ResponseStream.Current;

       ProcessResponse(response);
   }
}
catch (OperationCanceledException)
{
}
catch (RpcException ex)
{            
}
catch (Exception ex)
{           
}

Using .net 8 and Grpc.AspNetCore 2.71

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.