OrleansContrib / Orleans.Providers.MongoDB

A MongoDb implementation of the Orleans Providers: Membership, Storage and Reminders.
MIT License
100 stars 43 forks source link

CleanupDefunctSiloEntries broken for MultipleMembershipCollection #97

Closed nkindberg closed 1 year ago

nkindberg commented 2 years ago

We are using MongoDBMembershipStrategy.Muiltiple and noticed that we have a large number of defunct entries accumulating in the membership table which aren't getting cleaned-up as expected.

I believe this is related to DateTime vs. DateTimeOffset issues in the DeleteManyAsync call.

https://github.com/OrleansContrib/Orleans.Providers.MongoDB/blob/22bc56b54b9407453116d9f2294700e40992bdb4/Orleans.Providers.MongoDB/Membership/Store/Multiple/MultipleMembershipCollection.cs#L177-L180

x.Timestamp is a DateTime while beforeDate is a DateTimeOffset. The comparison between the two results in an implicit conversion to DateTimeOffset and a query filter like this being generated:

{{ "DeploymentId" : "My-Deployment-Id", "Status" : 6, "Timestamp" : { "$lt" : [NumberLong("637852876860000000"), 0] } }}

Zero results will be returned by this query because the DateTimeOffset is being converted to an array which cannot be compared against the date-formatted Timestamp field.