dapr: Mongodb state-store not working

When creating/configuring the state-store as mongodb, writing and initializing works correctly, but when trying to read some information from the state-store, a serialization error occurs.

Another point, when comparing the creation of the actors’ reminders partitions in other databases, such as PgSQL, in mongo db, every time the application is restarted, more N partitions of the reminders are created

Expected Behavior

Return state-store information

Actual Behavior

Exception when trying to deserialize information

[18:06:10 ERR] An unhandled exception has occurred while executing the request.
System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $.actorDetailsId | LineNumber: 0 | BytePositionInLine: 21.
 ---> System.FormatException: Either the JSON value is not in a supported format, or is out of bounds for an Int32.
   at System.Text.Json.Utf8JsonReader.GetInt32()
   at System.Text.Json.Serialization.Converters.Int32Converter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
   at Dapr.Actors.Runtime.DaprStateProvider.TryLoadStateAsync[T](String actorType, String actorId, String stateName, CancellationToken cancellationToken)
   at Dapr.Actors.Runtime.ActorStateManager.TryGetStateAsync[T](String stateName, CancellationToken cancellationToken)
   at DaprMongoDbBug.API.Actors.BugStateStoreActor.GetActorDetails() in /src/src/DaprMongoDbBug.API/Actors/BugStateStoreActorSample.cs:line 36
   at DaprMongoDbBug.API.Actors.BugStateStoreActor.ExecuteSampleReminder1() in /src/src/DaprMongoDbBug.API/Actors/BugStateStoreActorSample.cs:line 50
   at DaprMongoDbBug.API.Actors.BugStateStoreActor.ReceiveReminderAsync(String reminderName, Byte[] state, TimeSpan dueTime, TimeSpan period) in /src/src/DaprMongoDbBug.API/Actors/BugStateStoreActorSample.cs:line 71
   at Dapr.Actors.Runtime.ActorManager.<>c__DisplayClass24_0.<<FireReminderAsync>g__RequestFunc|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Dapr.Actors.Runtime.ActorManager.DispatchInternalAsync[T](ActorId actorId, ActorMethodContext actorMethodContext, Func`3 actorFunc, CancellationToken cancellationToken)
   at Dapr.Actors.Runtime.ActorManager.DispatchInternalAsync[T](ActorId actorId, ActorMethodContext actorMethodContext, Func`3 actorFunc, CancellationToken cancellationToken)
   at Dapr.Actors.Runtime.ActorManager.DispatchInternalAsync[T](ActorId actorId, ActorMethodContext actorMethodContext, Func`3 actorFunc, CancellationToken cancellationToken)
   at Dapr.Actors.Runtime.ActorManager.FireReminderAsync(ActorId actorId, String reminderName, Stream requestBodyStream, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Builder.ActorsEndpointRouteBuilderExtensions.<>c__DisplayClass4_0.<<MapReminderEndpoint>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Steps to Reproduce the Problem

Change the state-store host/server on “dapr/components/daprmongodbbug-statestore.yaml” I’ve attached an example ASP.Net core project, just run docker-compose (note there is a docker compose override)

Execute the sample project running the docker-compose, Navigate to: http://127.0.0.1:5200/swagger/index.html Execute the endpoint: createActor sending some paramters on model ( the field id is the actor id ) After this, try to read the actor details on the “GET” endpoint

DaprMongoDbBug.zip

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 27 (21 by maintainers)

Most upvoted comments

Quick update here:

If the content Type is specified as application/json then numbers will become double/float/decimal. That is in line with the JSON spec.

This will still happen with gRPC https://github.com/dapr/dapr/blob/master/pkg/grpc/api.go#L768

For other content types there is no concern here.

Note that in the case of HTTP the HTTP request JSON unmarshalling always unmarshalled any data value also, which is where the number data type was lost, regardless of content type. https://github.com/dapr/dapr/blob/master/pkg/http/api.go#L1268

I made a test using the Python SDK using gRPC + Mongo DB state store which shows that gRPC works is expected, with the caveat that in the case of explicit JSON content type integers will become decimals.

MicrosoftTeams-image (1)

gRPC is not impacted by this. As such we will be migrating the remaining SDKs to use the gRPC APIs for actors as soon as possible. We will migrate the .NET SDK in time for the 1.9 release.

Moving this to dapr/dapr as this issue is impacting documentdb state stores broadly.