<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:16:16 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>[CDRIVER-2765] new driver session support breaks application that is not designed with session</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-2765</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;Application using older c driver, e.g. 1.6, which does not support session is allowed to have following flow:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;using older version c driver api, get a client through client pool&lt;/li&gt;
	&lt;li&gt;construct a &lt;b&gt;find&lt;/b&gt;&#160;bson command&lt;/li&gt;
	&lt;li&gt;issue the command using&#160;&lt;b&gt;collectionCommandWithOpts&lt;/b&gt;&lt;/li&gt;
	&lt;li&gt;bson containing cursor id information is returned&lt;/li&gt;
	&lt;li&gt;construct a &lt;b&gt;getMore&lt;/b&gt;&#160;bson command using the cursor id&lt;/li&gt;
	&lt;li&gt;issue the command using&#160;&lt;b&gt;collectionCommandWithOpts&lt;/b&gt;&lt;/li&gt;
	&lt;li&gt;all batches are successfully returned&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;However, using c driver with newer version, the above flow is broken. Server will sometimes returns error in step (6) - &lt;b&gt;&quot;Cannot run getMore on cursor ..., which was created in session ...&quot;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The followings are some points about the causes:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;implicit session is implemented for cursor, however, its only implemented for&#160;mongoc_cursor_t returned api&lt;/li&gt;
	&lt;li&gt;session pool implemented in c driver will have chance to cause the &lt;b&gt;getMore&lt;/b&gt; command in (6) to acquire a new session or reused another pooled session, which is not same as the session used by &lt;b&gt;find&lt;/b&gt; command in (3)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;From the specification defined, with backward compatibility consideration, existing application is not required to make changes to run properly.&lt;/p&gt;

&lt;p&gt;Should we treat this issue as bug or should we change our application to adapt the driver session change?&lt;/p&gt;</description>
                <environment></environment>
        <key id="575929">CDRIVER-2765</key>
            <summary>new driver session support breaks application that is not designed with session</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</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="13201">Fixed</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="ben.prect">Ben Cheong</reporter>
                        <labels>
                    </labels>
                <created>Wed, 25 Jul 2018 09:08:09 +0000</created>
                <updated>Sat, 28 Oct 2023 11:29:41 +0000</updated>
                            <resolved>Thu, 16 Aug 2018 18:52:36 +0000</resolved>
                                    <version>1.11.0</version>
                                                    <component>libmongoc</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1977790" author="kevin.albertson" created="Thu, 16 Aug 2018 18:53:03 +0000"  >&lt;p&gt;Hi Ben, I&apos;m closing this ticket, but feel free to re-open if you&apos;re still having issues.&lt;/p&gt;</comment>
                            <comment id="1958275" author="ben.prect" created="Fri, 27 Jul 2018 11:21:55 +0000"  >&lt;p&gt;Hi Davis, thanks for the suggestion. We will try it.&lt;/p&gt;</comment>
                            <comment id="1958107" author="jesse" created="Fri, 27 Jul 2018 02:22:16 +0000"  >&lt;p&gt;I see, interesting. You can try calling mongoc_client_start_session in your program. If it fails that means the MongoDB server doesn&apos;t support sessions. If it succeeds, then you can explicitly add the session to each incoming user command with mongoc_client_session_append (session, opts). That way you&apos;re assured that &quot;find&quot; and &quot;getMore&quot; use the same session id.&lt;/p&gt;

&lt;p&gt;The server reaps sessions that have been idle for 30 minutes. So, track your session&apos;s age, and before you use it check if it&apos;s been idle for 29+ minutes. If it has, destroy it and create a new one.&lt;/p&gt;</comment>
                            <comment id="1958104" author="ben.prect" created="Fri, 27 Jul 2018 02:05:18 +0000"  >&lt;p&gt;We actually understand the helper functions are convenient to use, but it just increased the difficulty for our use case.&lt;/p&gt;

&lt;p&gt;our use case is like this:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;input: user input documented command by typing, e.g. { find: ... }&lt;/li&gt;
	&lt;li&gt;application: process the command by issuing c driver api, interacting with server&lt;/li&gt;
	&lt;li&gt;output: bson result from the call, and display to user&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;The whole feature is to let user tests the commands listed in mongodb documentation, we will need to do a parsing of the input and forward to different c driver helper calls. We could use that approach, but just found that using&#160;mongoc_collection_command_with_opts is more convenient for this use case.&lt;/p&gt;

&lt;p&gt;Anyway, we will review again the approach, thanks for the tips!&lt;/p&gt;</comment>
                            <comment id="1957212" author="jesse" created="Thu, 26 Jul 2018 11:39:05 +0000"  >&lt;p&gt;The best practice is to use C Driver helper functions instead of &quot;command&quot; functions whenever possible. So, use mongoc_collection_find_with_opts instead of running the &quot;find&quot; command directly with mongoc_collection_command_with_opts, and use mongoc_collection_insert_many instead of running the &quot;insert&quot; command directly, use mongoc_collection_aggregate instead of running the &quot;aggregate&quot; command directly, etc.&lt;/p&gt;

&lt;p&gt;The helper functions are provided to you to implement special logic specific to those commands. For example, the &quot;aggregate&quot; command requires that you send the same session with both &quot;aggregate&quot; and &quot;getMore&quot;, the same as the &quot;find&quot; command does. The mongoc_collection_aggregate helper implements this session logic for you, but if you run the &quot;aggregate&quot; command directly you&apos;ll have difficulty.&lt;/p&gt;

&lt;p&gt;Similarly for the &quot;insert&quot; command: the mongoc_collection_insert_many helper ensures that you properly split multiple documents into batches of 1000 documents or 16 MB each. This is difficult to implement yourself if you call &quot;insert&quot; with mongoc_collection_command_with_opts.&lt;/p&gt;

&lt;p&gt;I recommend that you use the C Driver&apos;s helper functions whenever we provide them to you. We provide them for a reason!&lt;/p&gt;</comment>
                            <comment id="1957102" author="ben.prect" created="Thu, 26 Jul 2018 06:36:17 +0000"  >&lt;p&gt;Hi Davis, our application intention is to use documented commands solely, and show these commands to users according to the MongoDB documentation (e.g. &lt;a href=&quot;https://docs.mongodb.com/manual/reference/method/db.collection.find,&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.com/manual/reference/method/db.collection.find&lt;/a&gt;&#160;and &lt;a href=&quot;https://docs.mongodb.com/manual/reference/command/getMore/#dbcmd.getMore&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.com/manual/reference/command/getMore/#dbcmd.getMore&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;We used&#160;mongoc_collection_command_with_opts instead of&#160;mongoc_collection_find_with_opts, since such call allows us to use the same call for all documented commands, and allows us to have a general coding structure to handle our feature.&lt;/p&gt;

&lt;p&gt;We are not aware of session changes until we tried to upgrade the c driver to a newer version. If c driver does not handle implicit session for find + getMore commands case, we have to either overhaul our internal to use cursor returned approach, which we want to avoid, or we have to use explicit session on top of all current flows.&lt;/p&gt;

&lt;p&gt;Do you expect application use explicit session for all session supported c driver api whenever possible, as a good practice?&lt;/p&gt;</comment>
                            <comment id="1956094" author="jesse" created="Wed, 25 Jul 2018 12:43:05 +0000"  >&lt;p&gt;Hi, thanks for the report. Can you tell me why you&apos;re constructing find and getMore commands using mongoc_collection_command_with_opts? We intend for you to use mongoc_collection_find_with_opts to create a cursor, and mongoc_cursor_next to retrieve results.&lt;/p&gt;</comment>
                            <comment id="1956010" author="ben.prect" created="Wed, 25 Jul 2018 09:16:37 +0000"  >&lt;p&gt;typo:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;collectionCommandWithOpts&lt;/b&gt; is mongoc_collection_command_with_opts in c driver api&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|htu2gn:</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>