<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:47:31 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-4199] Change stream exception on update notification after some hours of usage</title>
                <link>https://jira.mongodb.org/browse/CSHARP-4199</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;h4&gt;&lt;a name=&quot;Summary&quot;&gt;&lt;/a&gt;Summary&lt;/h4&gt;

&lt;p&gt;After some hours of usage, the access to the UpdateDescription property of the change stream &lt;b&gt;update&lt;/b&gt; notification gives a format exception.&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;MongoDBdriverversion2.11.4againstAtlasSharedFree5.0.8.&quot;&gt;&lt;/a&gt;MongoDB driver version 2.11.4 against Atlas Shared Free 5.0.8.&lt;/h4&gt;
&lt;h4&gt;&lt;a name=&quot;HowtoReproduce&quot;&gt;&lt;/a&gt;How to Reproduce&lt;/h4&gt;

&lt;p&gt;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 &lt;b&gt;update&lt;/b&gt; notification gives an exception (I&apos;ve checked in the Watch pane).&lt;/p&gt;

&lt;p&gt;The exception stack is the following:&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &lt;em&gt;System.FormatException: Invalid field name: &quot;truncatedArrays&quot;.&lt;/em&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160;&lt;em&gt;at MongoDB.Driver.ChangeStreamUpdateDescriptionSerializer.DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)&lt;/em&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160;&lt;em&gt;at MongoDB.Bson.Serialization.Serializers.SealedClassSerializerBase`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)&lt;/em&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160;&lt;em&gt;at MongoDB.Bson.Serialization.Serializers.SerializerBase`1.MongoDB.Bson.Serialization.IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)&lt;/em&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160;&lt;em&gt;at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize(IBsonSerializer serializer, BsonDeserializationContext context)&lt;/em&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160;&lt;em&gt;at MongoDB.Bson.Serialization.BsonSerializationInfo.DeserializeValue(BsonValue value)&lt;/em&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160;&lt;em&gt;at MongoDB.Bson.Serialization.BsonDocumentBackedClass.GetValue&lt;span class=&quot;error&quot;&gt;&amp;#91;T&amp;#93;&lt;/span&gt;(String memberName, T defaultValue)&lt;/em&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160;&lt;em&gt;at MongoDB.Driver.ChangeStreamDocument`1.get_UpdateDescription()&lt;/em&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160;&lt;em&gt;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&lt;/em&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160;&lt;em&gt;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&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;AdditionalBackground&quot;&gt;&lt;/a&gt;Additional Background&lt;/h4&gt;

&lt;p&gt;Here is the code where the exception happens. I&apos;ll patch by catching and ignoring the case, but it means for the application to miss a notification.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; __&#160; &#160; &#160; &#160; &#160; &#160; var client = new MongoClient(observedCollection.ConnectionString);&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; var database = client.GetDatabase(observedCollection.DatabaseName);&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; var collection = database.GetCollection&amp;lt;BsonDocument&amp;gt;(observedCollection.CollectionName);&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; while (stoppingToken.IsCancellationRequested == false)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; ChangeStreamOptions opts = new();&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; using var cursor = await collection.WatchAsync(opts, stoppingToken);&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; while (await cursor.MoveNextAsync(stoppingToken))&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; foreach (ChangeStreamDocument&amp;lt;BsonDocument&amp;gt; change in cursor.Current)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; handler(&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Convert(room, change)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; );&lt;/tt&gt;&lt;br/&gt;
{{&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }}}&lt;br/&gt;
{{&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }}}&lt;br/&gt;
{{&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }}}&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; // ...&lt;/tt&gt;{{&#160; &#160; &#160; &#160; }}&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&#160; &#160; &#160; &#160; private static IMongoChangeStreamDocument Convert(&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; string room,&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; ChangeStreamDocument&amp;lt;BsonDocument&amp;gt; change&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; )&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; ChangeStreamUpdateDescription? updateDescription = null;&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; switch (change.OperationType)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; case ChangeStreamOperationType.Insert:&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; break;&lt;/tt&gt;&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; case ChangeStreamOperationType.Update:&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; updateDescription = change.UpdateDescription;&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; break;&lt;/tt&gt;&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; case ChangeStreamOperationType.Delete:&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; break;&lt;/tt&gt;&lt;br/&gt;
{{&#160; &#160; &#160; &#160; &#160; &#160; }}}&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; return new MongoChangeStreamDocumentMessage(&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; room,&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; MongoHelpers.OidToString(change.DocumentKey)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; )&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; OperationType = change.OperationType,&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; FullDocument = change.FullDocument,&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; UpdateDescription = updateDescription,&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; };&lt;/tt&gt;&lt;br/&gt;
{{&#160; &#160; &#160; &#160; }}}&lt;/p&gt;</description>
                <environment></environment>
        <key id="2063288">CSHARP-4199</key>
            <summary>Change stream exception on update notification after some hours of usage</summary>
                <type id="6" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14720&amp;avatarType=issuetype">Question</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="13203">Gone away</resolution>
                                        <assignee username="james.kovacs@mongodb.com">James Kovacs</assignee>
                                    <reporter username="vernarim@libero.it">Mario Vernari</reporter>
                        <labels>
                    </labels>
                <created>Tue, 7 Jun 2022 03:18:15 +0000</created>
                <updated>Fri, 27 Oct 2023 19:56:03 +0000</updated>
                            <resolved>Thu, 30 Jun 2022 12:00:58 +0000</resolved>
                                    <version>2.11.4</version>
                                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="4650125" author="dbeng-pm-bot" created="Thu, 30 Jun 2022 12:00:59 +0000"  >&lt;p&gt;There hasn&apos;t been any recent activity on this ticket, so we&apos;re resolving it. Thanks for reaching out! Please feel free to comment on this if you&apos;re able to provide more information.&lt;/p&gt;</comment>
                            <comment id="4619376" author="james.kovacs" created="Wed, 15 Jun 2022 23:34:18 +0000"  >&lt;p&gt;Hi, &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=vernarim%40libero.it&quot; class=&quot;user-hover&quot; rel=&quot;vernarim@libero.it&quot;&gt;vernarim@libero.it&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;We are glad that you were able to find a solution and thank you for your question. MongoDB does advertise its supported wire versions via the &lt;tt&gt;hello&lt;/tt&gt; command (formerly called &lt;tt&gt;isMaster&lt;/tt&gt;). It will reply with a &lt;tt&gt;minWireVersion&lt;/tt&gt; and &lt;tt&gt;maxWireVersion&lt;/tt&gt;. Drivers know their supported wire versions. For example, the 2.14.0 driver - which requires MongoDB 3.6+ - has a &lt;tt&gt;minWireVersion&lt;/tt&gt; of 6. If you try to connect to a MongoDB 3.4 server using the 2.14.0 driver, you would receive an error stating that the wire versions aren&apos;t compatible as the server&apos;s &lt;tt&gt;maxWireVersion&lt;/tt&gt; is 5 and the driver&apos;s &lt;tt&gt;minWireVersion&lt;/tt&gt; is 6.&lt;/p&gt;

&lt;p&gt;So far so good. The question now becomes why doesn&apos;t the driver raise an exception if the server&apos;s &lt;tt&gt;maxWireVersion&lt;/tt&gt; is higher than the driver&apos;s? The reason is that a lot of times it doesn&apos;t matter. As long as you&apos;re not using new features introduced in later versions of MongoDB, older clients will most often work. And if you try to use a new server feature with an old driver, you will quickly know whether it works or not. You encountered a bit of an unfortunate edge case where you start an operation (a change stream) and you might not see a change stream event with the new &lt;tt&gt;truncatedArrays&lt;/tt&gt; field for hours. Depending on your workload, you may never see this field. Thus we made the choice to rely on &lt;a href=&quot;https://www.mongodb.com/docs/drivers/csharp/#compatibility&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;human-readable compatibility matrices&lt;/a&gt; rather than not allowing developers to use older drivers with newer servers.&lt;/p&gt;

&lt;p&gt;We are investing in better forward compatibility guarantees with features like the &lt;a href=&quot;https://www.mongodb.com/docs/manual/reference/stable-api/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;MongoDB Stable API&lt;/a&gt; as well as making our APIs more tolerant of future changes such as &lt;a href=&quot;https://jira.mongodb.org/browse/DRIVERS-1995&quot; title=&quot;Do not error when parsing change stream event documents&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DRIVERS-1995&quot;&gt;DRIVERS-1995&lt;/a&gt; / &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4036&quot; title=&quot;Do not error when parsing change stream event documents&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4036&quot;&gt;&lt;del&gt;CSHARP-4036&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Please let us know if you have any additional questions.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                            <comment id="4605947" author="JIRAUSER1257742" created="Thu, 9 Jun 2022 21:53:08 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=vernarim%40libero.it&quot; class=&quot;user-hover&quot; rel=&quot;vernarim@libero.it&quot;&gt;vernarim@libero.it&lt;/a&gt;, thank you for your question.&lt;br/&gt;
As you discovered, this issue (&lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-3212&quot; title=&quot;Add new field truncatedArrays into cursor.nextBatch.updateDescription&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-3212&quot;&gt;&lt;del&gt;CSHARP-3212&lt;/del&gt;&lt;/a&gt;) was resolved in 2.12.0 driver version.&lt;/p&gt;

&lt;p&gt;.Net driver has &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#checking-wire-protocol-compatibility&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;versions range&lt;/a&gt; validation. We will look deeper into what the expected behaviour should be in such case.&lt;/p&gt;</comment>
                            <comment id="4604993" author="vernarim@libero.it" created="Thu, 9 Jun 2022 15:47:06 +0000"  >&lt;p&gt;Okay, the problem seems solved. It is the driver version, which is not compatible with the Atlas MongoDB version. I upgraded it to version 2.13.3 and now everything seems working fine. I had to limit to that version because the same app must connect to an old Mongo 3.4: this driver is the only able to fit practically any MongoDB version.&lt;/p&gt;

&lt;p&gt;Just a question: why don&apos;t you implement the compatibility matrix inside the driver, so that it&apos;ll raise an exception SOON when the server doesn&apos;t fit? it isn&apos;t nice allowing the connection, then having strange behaviors after the app is released.&lt;/p&gt;</comment>
                            <comment id="4598497" author="vernarim@libero.it" created="Tue, 7 Jun 2022 03:39:51 +0000"  >&lt;p&gt;Isn&apos;t a way to edit the post? the code seems now full of garbage...&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i0gk4w:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>