Details
-
Question
-
Resolution: Gone away
-
Unknown
-
None
-
2.11.4
-
None
-
None
Description
Summary
After some hours of usage, the access to the UpdateDescription property of the change stream update notification gives a format exception.
MongoDB driver version 2.11.4 against Atlas Shared Free 5.0.8.
How to Reproduce
Not easy to reproduce, but it happens regularly after some hours of usage. Once happened while debugging in Visual Studio and it seems the simple access to the UpdateDescription property of an update notification gives an exception (I've checked in the Watch pane).
The exception stack is the following:
System.FormatException: Invalid field name: "truncatedArrays".
at MongoDB.Driver.ChangeStreamUpdateDescriptionSerializer.DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
at MongoDB.Bson.Serialization.Serializers.SealedClassSerializerBase`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
at MongoDB.Bson.Serialization.Serializers.SerializerBase`1.MongoDB.Bson.Serialization.IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize(IBsonSerializer serializer, BsonDeserializationContext context)
at MongoDB.Bson.Serialization.BsonSerializationInfo.DeserializeValue(BsonValue value)
at MongoDB.Bson.Serialization.BsonDocumentBackedClass.GetValue[T](String memberName, T defaultValue)
at MongoDB.Driver.ChangeStreamDocument`1.get_UpdateDescription()
at Cet.Core.Web.MongoDB.MongoChangeStreamAdapter.Convert(String room, ChangeStreamDocument`1 change) in C:\DotNet18\Cet.Core.Web\Cet.Core.Web\MongoDB\Listeners\MongoChangeStreamAdapter.cs:line 134
at Cet.Core.Web.MongoDB.MongoChangeStreamAdapter.ListenCollectionAsync(IReadOnlyMongoListenerConnectionOptions observedCollection, Action`1 handler, ILogger logger, CancellationToken stoppingToken) in C:\DotNet18\Cet.Core.Web\Cet.Core.Web\MongoDB\Listeners\MongoChangeStreamAdapter.cs:line 98
Additional Background
Here is the code where the exception happens. I'll patch by catching and ignoring the case, but it means for the application to miss a notification.
__ var client = new MongoClient(observedCollection.ConnectionString);
var database = client.GetDatabase(observedCollection.DatabaseName);
var collection = database.GetCollection<BsonDocument>(observedCollection.CollectionName);
while (stoppingToken.IsCancellationRequested == false)
{
ChangeStreamOptions opts = new();
using var cursor = await collection.WatchAsync(opts, stoppingToken);
while (await cursor.MoveNextAsync(stoppingToken))
{
foreach (ChangeStreamDocument<BsonDocument> change in cursor.Current)
{
handler(
Convert(room, change)
);
{{ }}}
{{ }}}
{{ }}}
// ...{{ }}
private static IMongoChangeStreamDocument Convert(
string room,
ChangeStreamDocument<BsonDocument> change
)
{
ChangeStreamUpdateDescription? updateDescription = null;
switch (change.OperationType)
{
case ChangeStreamOperationType.Insert:
break; case ChangeStreamOperationType.Update:
updateDescription = change.UpdateDescription;
break; case ChangeStreamOperationType.Delete:
break;
{{ }}}
return new MongoChangeStreamDocumentMessage(
room,
MongoHelpers.OidToString(change.DocumentKey)
)
{
OperationType = change.OperationType,
FullDocument = change.FullDocument,
UpdateDescription = updateDescription,
};
{{ }}}