Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DaprClient.GetMetadataAsync() throwing Exception #1349

Closed
sanjeev-saxena-us opened this issue Sep 5, 2024 · 4 comments · Fixed by #1353
Closed

DaprClient.GetMetadataAsync() throwing Exception #1349

sanjeev-saxena-us opened this issue Sep 5, 2024 · 4 comments · Fixed by #1353
Assignees
Labels
kind/bug Something isn't working

Comments

@sanjeev-saxena-us
Copy link

Dapr.Client .NET package, this used to work in 1.10 but appears to be broken in 1.12 onwards; is now throwing a "Object reference not set to an instance". Have tried with 1.14 and same issue.

@sanjeev-saxena-us sanjeev-saxena-us added the kind/bug Something isn't working label Sep 5, 2024
@yaron2 yaron2 transferred this issue from dapr/dapr Sep 23, 2024
@alicejgibbons
Copy link

alicejgibbons commented Oct 3, 2024

Able to reproduce (1.14.4, dotnet 1.14.0) with the following findings:

  • only happens when app-port (app channel) argument is set but app channel is not yet established by daprd
  • Running without app channel or when daprd has discovered the app already allows DaprClient.GetMetadataAsync() to work fine.

Eg. Running a sample dotnet app like the following works fine, regardless of where the GetMetadataAsync() command is
dapr run --app-id DaprClient --dapr-http-port 5780 --dapr-grpc-port 5701 -- dotnet run

But running
dapr run --app-id DaprClient --app-port 5292 --dapr-http-port 5780 --dapr-grpc-port 5701 -- dotnet run fails with the following error when calling GetMetadataAsync() before the application has been discovered on specified port. Before "application discovered on port 5292" log line printed in daprd.

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Dapr.Client.DaprClientGrpc.GetMetadataAsync(CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in /Users/alicegibbons/Documents/Customers/Alegeus/DaprClientTest/TodoApi/Program.cs:line 15
   at Program.<Main>(String[] args)

@JoshVanL
Copy link
Contributor

JoshVanL commented Oct 3, 2024

Based on my limited DotNet experience, I believe the issue here is that the DotNet client method is not checking for a nil pointer of the gRPC message for ActorRuntime. It is currently the case that ActorRuntime in the Metadata message will be nil until the app port is available and read by daprd.

&runtime.GetMetadataResponse{state:impl.MessageState{NoUnkeyedLiterals:pragma.NoUnkeyedLiterals{}, DoNotCompare:pragma.DoNotCompare{}, DoNotCopy:pragma.DoNotCopy{}, atomicMessageInfo:(*impl.MessageInfo)(0xc0003d95d0)}, sizeCache:0, unknownFields:[]uint8(nil), Id:"cd4386a7-c513-4d72-bd2c-c808e6f63e55", ActiveActorsCount:[]*runtime.ActiveActorsCount(nil), RegisteredComponents:[]*runtime.RegisteredComponents(nil), ExtendedMetadata:map[string]string{"daprRuntimeVersion":"edge"}, Subscriptions:[]*runtime.PubsubSubscription(nil), HttpEndpoints:[]*runtime.MetadataHTTPEndpoint(nil), AppConnectionProperties:(*runtime.AppConnectionProperties)(0xc00088d860), RuntimeVersion:"edge", EnabledFeatures:[]string(nil), ActorRuntime:(*runtime.ActorRuntime)(nil)}
&runtime.GetMetadataResponse{state:impl.MessageState{NoUnkeyedLiterals:pragma.NoUnkeyedLiterals{}, DoNotCompare:pragma.DoNotCompare{}, DoNotCopy:pragma.DoNotCopy{}, atomicMessageInfo:(*impl.MessageInfo)(0xc0003d95d0)}, sizeCache:0, unknownFields:[]uint8(nil), Id:"cd4386a7-c513-4d72-bd2c-c808e6f63e55", ActiveActorsCount:[]*runtime.ActiveActorsCount(nil), RegisteredComponents:[]*runtime.RegisteredComponents(nil), ExtendedMetadata:map[string]string{"daprRuntimeVersion":"edge"}, Subscriptions:[]*runtime.PubsubSubscription(nil), HttpEndpoints:[]*runtime.MetadataHTTPEndpoint(nil), AppConnectionProperties:(*runtime.AppConnectionProperties)(0xc00088de00), RuntimeVersion:"edge", EnabledFeatures:[]string(nil), ActorRuntime:(*runtime.ActorRuntime)(0xc00088de60)}
ActorRuntime:(*runtime.ActorRuntime)(nil)}
ActorRuntime:(*runtime.ActorRuntime)(0xc00088de60)}

@marcduiker
Copy link
Contributor

Same issue as #1296

@WhitWaldo
Copy link
Contributor

WhitWaldo commented Oct 6, 2024

@marcduiker Thanks for finding the duplicate!

@JoshVanL Your conclusion looks accurate to me. We have a lot of opportunities for .NET client improvement here:

  • There's no unit test coverage for the GetMetadataAsync method or return type
  • Lack of nullability annotations

I've created a PR with a fix for this issue and a separate pending PR that adds nullability annotations, so we can hopefully keep a few more of these from slipping through the cracks soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants