Skip to content

Null Reference on exception in OnConnecting #970

@Rurouni

Description

@Rurouni

Hi,

There is a regression in 7.0.5 that leads to NullReferenceException if you throw any exception in OnConnecting method
For example:

protected override ValueTask OnConnecting()
{
    throw new ReturnStatusException(StatusCode.FailedPrecondition, "Some error");
    return base.OnConnecting();
}
  • In 7.0.4 and below this leads to correctly rethrowing exception on the client side with correct status code

  • In 7.0.5 and above this leads to such additional exception on the server side

Grpc.AspNetCore.Server.ServerCallHandler[6]
      Error when executing service method 'Connect'.
      System.NullReferenceException: Object reference not set to an instance of an object.
         at MagicOnion.Server.Hubs.StreamingHubBase`2.MagicOnion.Server.Internal.IStreamingHubBase.Connect()
         at MagicOnion.Server.Binder.Internal.MagicOnionGrpcMethodHandler`1.<>c__DisplayClass9_0`4.<<BuildDuplexStreamingMethod>g__InvokeAsync|1>d.MoveNext()
      --- End of stack trace from previous location ---
         at Grpc.Shared.Server.DuplexStreamingServerMethodInvoker`3.Invoke(HttpContext httpContext, ServerCallContext serverCallContext, IAsyncStreamReader`1 requestStream, IServerStreamWriter`1 responseStream)
         at Grpc.Shared.Server.DuplexStreamingServerMethodInvoker`3.Invoke(HttpContext httpContext, ServerCallContext serverCallContext, IAsyncStreamReader`1 requestStream, IServerStreamWriter`1 responseStream)
         at Grpc.AspNetCore.Server.Internal.CallHandlers.DuplexStreamingServerCallHandler`3.HandleCallAsyncCore(HttpContext httpContext, HttpContextServerCallContext serverCallContext)
         at Grpc.AspNetCore.Server.Internal.CallHandlers.ServerCallHandlerBase`3.<HandleCallAsync>g__AwaitHandleCall|8_0(HttpContextServerCallContext serverCallContext, Method`2 method, Task handleCall)

and Unknown status code on the client

Grpc.Core.RpcException: Status(StatusCode="Unknown", Detail="Exception was thrown by handler.")
   at MagicOnion.Client.StreamingHubClientBase`2.__ConnectAndSubscribeAsync(CancellationToken connectAndSubscribeCancellationToken)
   at MagicOnion.Client.StreamingHubClient.ConnectAsync[TStreamingHub,TReceiver](CallInvoker callInvoker, TReceiver receiver, StreamingHubClientOptions options, IStreamingHubClientFactoryProvider factoryProvider, CancellationToken cancellationToken)
   at MagicOnion.Client.StreamingHubClient.ConnectAsync[TStreamingHub,TReceiver](ChannelBase channel, TReceiver receiver, StreamingHubClientOptions options, IStreamingHubClientFactoryProvider factoryProvider, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in 

Thank you

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions