<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:01:07 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>[JAVA-4050] Driver validates it is the creator of a session before using it</title>
                <link>https://jira.mongodb.org/browse/JAVA-4050</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Server sessions can be reused by the same database user who created them even across different connections and applications, but the Java driver validates that any session reference passed in is from the same MongoClient:&lt;/p&gt;

&lt;p&gt;Exception: java.lang.IllegalStateException: state should be: ClientSession from same MongoClient&lt;/p&gt;

&lt;p&gt;Source:&#160;&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/d57dfa8af686180239058a06eca838e18bfe5cdd/driver-sync/src/main/com/mongodb/client/internal/MongoClientDelegate.java#L259&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/blob/d57dfa8af686180239058a06eca838e18bfe5cdd/driver-sync/src/main/com/mongodb/client/internal/MongoClientDelegate.java#L259&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are circumstances where 2 different connections are using the same MongoClient and using the same session. (We are using this case for integrity testing of some replica set operations involving IP resolution changes, where 1 mongoclient is connected to an old IP via a proxy, and 1 is connected to a new IP via a proxy).&lt;/p&gt;

&lt;p&gt;I have tried to work around this validation by using runCommand() with an explicit `lsid` operation like so:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;final Document result =&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; pClient&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; .getDatabase(&quot;test&quot;)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; .runCommand(&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; new Document(&quot;find&quot;, &quot;test&quot;)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; .append(&quot;sort&quot;, new BsonDocument(&quot;i&quot;, new BsonInt32(1)))&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; }}{{.append(&quot;batchSize&quot;, 0)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; }}{{.append(&quot;lsid&quot;, _sessionIdent));&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;But it appears in this case, the driver implicitly creates a new session and assigns a second `lsid` property, causing this server duplicate bson field error:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;com.mongodb.MongoCommandException: Command failed with error 40413 (Location40413): &apos;BSON field &apos;APIParametersFromClient.lsid&apos; is a duplicate field&apos; on server xxx-hostname-here-xxx:27017. The full response is {&quot;ok&quot;: 0.0, &quot;errmsg&quot;: &quot;BSON field &apos;APIParametersFromClient.lsid&apos; is a duplicate field&quot;, &quot;code&quot;: 40413, &quot;codeName&quot;: &quot;Location40413&quot;, &quot;$clusterTime&quot;: {&quot;clusterTime&quot;: {&quot;$timestamp&quot;: {&quot;t&quot;: 1615894777, &quot;i&quot;: 1&lt;/tt&gt;, &quot;signature&quot;: {&quot;hash&quot;: &lt;/p&gt;
{&quot;$binary&quot;: &quot;XQL3Tqirs9PAzLVPXsuKQHdxE4E=&quot;, &quot;$type&quot;: &quot;00&quot;}
&lt;p&gt;, &quot;keyId&quot;: {&quot;$numberLong&quot;: &quot;6939936267161305090&quot;}}}, &quot;operationTime&quot;: {&quot;$timestamp&quot;: &lt;/p&gt;
{&quot;t&quot;: 1615894777, &quot;i&quot;: 1}
&lt;p&gt;}}}}&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;2 questions:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Is there some way we can make use of a session ID created outside the MongoClient performing the operation, without driver code changes?&lt;/li&gt;
	&lt;li&gt;It seems the server supports the operation, is the validation in question is superfluous and can it be removed?&lt;/li&gt;
&lt;/ul&gt;
</description>
                <environment></environment>
        <key id="1649746">JAVA-4050</key>
            <summary>Driver validates it is the creator of a session before using it</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="13202">Works as Designed</resolution>
                                        <assignee username="ross@mongodb.com">Ross Lawley</assignee>
                                    <reporter username="jack.wearden@mongodb.com">Jack Wearden</reporter>
                        <labels>
                    </labels>
                <created>Tue, 16 Mar 2021 11:56:45 +0000</created>
                <updated>Fri, 27 Oct 2023 13:20:57 +0000</updated>
                            <resolved>Tue, 16 Mar 2021 12:37:05 +0000</resolved>
                                                                    <component>Session Management</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="3666291" author="jack.wearden" created="Tue, 16 Mar 2021 12:36:44 +0000"  >&lt;p&gt;Thanks for that spec Ross, that is really helpful - I had learned sessions were not scoped to connections, but I didn&apos;t realise they were scoped to a client.&lt;/p&gt;

&lt;p&gt;The original observation in this ticket no longer makes sense given that ticket, so I&apos;ll close it out and try another strategy.&lt;/p&gt;</comment>
                            <comment id="3666254" author="ross@10gen.com" created="Tue, 16 Mar 2021 12:10:53 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jack.wearden&quot; class=&quot;user-hover&quot; rel=&quot;jack.wearden&quot;&gt;jack.wearden&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;This is as per specification see the &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/sessions/driver-sessions.rst&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;driver sessions specification&lt;/a&gt;. It may be worth reaching out to the authors and / or creating a HELP ticket for the feature.&lt;/p&gt;

&lt;p&gt;Please note: any changes to behaviour would require changes to this specification.&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                            <comment id="3666244" author="jack.wearden" created="Tue, 16 Mar 2021 12:03:08 +0000"  >&lt;p&gt;And possibly a third suggestion - when a user has explicitly attached an `lsid`, could the driver skip adding its own?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                                        </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <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_10257" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Documentation Changes</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="11861"><![CDATA[Not Needed]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hyku87:</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>