[CSHARP-2918] Watch method should work even when documents contain duplicate element names Created: 28/Jan/20  Updated: 28/Oct/23  Resolved: 06/Apr/20

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.9.1
Fix Version/s: 2.10.3, 2.11.0

Type: Bug Priority: Major - P3
Reporter: Jessica Wyatt Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

When calling MoveNext() on an IAsyncCursor<ChangeStreamDocument<T>> where the next change in the oplog is for a document that contains a duplicate element MoveNext() throws an InvalidOperationException with the message, "Duplicate element name '<ElementName>'."

I can find no way to extract the ID of the document that caused this exception to occur from the change stream and no way to easily find documents with duplicate elements by any other means.

Obviously you're not meant to have duplicate elements and we certainly try and keep them out of our data but on the odd occasion that it does slip in it is nearly impossible to find and it cripples our use of the change streams because there's no way to get the document ID or skip over the offending document.



 Comments   
Comment by Githook User [ 06/Apr/20 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-2918: Fix race condition in test.
Branch: v2.10.x
https://github.com/mongodb/mongo-csharp-driver/commit/a03f404e4aeb74f8afae0cf3e8d22d009b90c657

Comment by Githook User [ 06/Apr/20 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-2918: Watch method should work even when documents contain duplicate element names.
Branch: v2.10.x
https://github.com/mongodb/mongo-csharp-driver/commit/9f972a347f16d3bbcbc42ad881201a8a55e949a0

Comment by Githook User [ 27/Mar/20 ]

Author:

{'email': 'robert@robertstam.org', 'name': 'rstam', 'username': 'rstam'}

Message: CSHARP-2918: Fix race condition in test.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/b1b5d2cf9eb7773a94f3cab275edd900113e134e

Comment by Githook User [ 12/Mar/20 ]

Author:

{'name': 'rstam', 'username': 'rstam', 'email': 'robert@robertstam.org'}

Message: CSHARP-2918: Watch method should work even when documents contain duplicate element names.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/39c3cc4f2aec0d0367e0023cdf5e76edee0c4991

Comment by Robert Stam [ 04/Mar/20 ]

Thank you for reporting this. I am able to reproduce it with a small test program.

I will be changing the driver so that the Watch method works even when documents contain duplicate element names.

Comment by Jessica Wyatt [ 26/Feb/20 ]

Apologies for the long delay; it's been a busy few weeks. Here is the requested stack trace:

System.InvalidOperationException:
at MongoDB.Bson.BsonDocument.Add (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.BsonDocument.Add (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.Serializers.BsonDocumentSerializer.DeserializeValue (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.Serializers.BsonValueSerializerBase`1.Deserialize (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.Serializers.BsonValueSerializer.DeserializeValue (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.Serializers.BsonValueSerializerBase`1.Deserialize (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.Serializers.BsonDocumentSerializer.DeserializeValue (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.Serializers.BsonValueSerializerBase`1.Deserialize (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.BsonDocumentBackedClassSerializer`1.DeserializeValue (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.Serializers.ClassSerializerBase`1.Deserialize (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize (MongoDB.Bson, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Driver.Core.Operations.ChangeStreamCursor`1.DeserializeDocument (MongoDB.Driver.Core, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Driver.Core.Operations.ChangeStreamCursor`1.DeserializeDocuments (MongoDB.Driver.Core, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Driver.Core.Operations.ChangeStreamCursor`1.ProcessBatch (MongoDB.Driver.Core, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)
at MongoDB.Driver.Core.Operations.ChangeStreamCursor`1.MoveNext (MongoDB.Driver.Core, Version=2.9.1.0, Culture=neutral, PublicKeyToken=null)

Comment by Jessica Wyatt [ 03/Feb/20 ]

Hi Esha,

Thanks for looking into this. I will be able to send a stack trace but unfortunately it'll be a few weeks until I can as my manager has moved me onto something else for the time being and I'd need to create a minimal reproducible example as my employer isn't happy with me uploading a stack trace from our actual code base.

Comment by Esha Bhargava [ 03/Feb/20 ]

chris.wyatt@livinglens.tvCan you send us a stack trace?

Generated at Wed Feb 07 21:43:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.