<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:24:53 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>[DRIVERS-2165] Consider allowing (async) drivers to use locks to prevent concurrent ClientSession usage</title>
                <link>https://jira.mongodb.org/browse/DRIVERS-2165</link>
                <project id="10980" key="DRIVERS">Drivers</project>
                    <description>&lt;p&gt;In an asynchronous driver, it is easy for users to accidentally use a &lt;tt&gt;ClientSession&lt;/tt&gt;&#160;concurrently for multiple operations. (see &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-43889&quot; title=&quot;Distinguish between a retryable write and a transaction when failing a command&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-43889&quot;&gt;&lt;del&gt;SERVER-43889&lt;/del&gt;&lt;/a&gt; for an example of a user doing this in the C# driver.)&lt;/p&gt;

&lt;p&gt;Without some kind of locking mechanism built into &lt;tt&gt;ClientSession&lt;/tt&gt;,&#160;the best we can do is thoroughly document that sessions can only be used by one operation at once and that users need to await the result of one operation before firing off another.&lt;/p&gt;

&lt;p&gt;Right now, the spec explicitly says:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Drivers MUST NOT attempt to detect simultaneous use by multiple threads or processes&#160;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;(rationale &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/sessions/driver-sessions.rst#why-do-we-say-drivers-must-not-attempt-to-detect-unsafe-multi-threaded-or-multi-process-use-of-clientsession&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;here&lt;/a&gt;). We should consider amending the spec to allow drivers to make their &lt;tt&gt;ClientSession&lt;/tt&gt; types thread-safe.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1017495">DRIVERS-2165</key>
            <summary>Consider allowing (async) drivers to use locks to prevent concurrent ClientSession usage</summary>
                <type id="14901" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14700&amp;avatarType=issuetype">Spec Change</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="3">Duplicate</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="kaitlin.mahar@mongodb.com">Kaitlin Mahar</reporter>
                        <labels>
                    </labels>
                <created>Thu, 21 Nov 2019 05:15:12 +0000</created>
                <updated>Thu, 1 Sep 2022 21:41:02 +0000</updated>
                            <resolved>Thu, 1 Sep 2022 21:40:34 +0000</resolved>
                                                        <component>Sessions</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4796693" author="shane.harvey" created="Thu, 1 Sep 2022 21:40:43 +0000"  >&lt;p&gt;Closing as a duplicate of DRIVERS-1012.&lt;/p&gt;</comment>
                            <comment id="2723289" author="shane.harvey" created="Mon, 13 Jan 2020 22:51:47 +0000"  >&lt;p&gt;The full rationale in the spec:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;Drivers MUST NOT attempt to detect unsafe multi-threaded or multi-process use of ClientSession&amp;#93;&lt;/span&gt; because doing so would provide an illusion of safety. It doesn&apos;t make these instances thread safe. And even if when testing an application no such exceptions are encountered, that doesn&apos;t prove anything. The application might still be using the instances in a thread-unsafe way and just didn&apos;t happen to do so during a test run. The final argument is that checking this would require overhead that doesn&apos;t provide any clear benefit.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I think one clear benefit of detecting concurrent ClientSession usage, especially for async APIs, is that we can raise an informative error to the user that something is wrong. The buggy example in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-43889&quot; title=&quot;Distinguish between a retryable write and a transaction when failing a command&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-43889&quot;&gt;&lt;del&gt;SERVER-43889&lt;/del&gt;&lt;/a&gt; is easy to write. Moreover, the server may not always return an error in this case and even when it does the error is not easy for a user to diagnose (eg &quot;Cannot start transaction 1 on session &amp;lt;&amp;gt; because a newer transaction 3 has already started&quot;).&lt;/p&gt;

&lt;p&gt;However, one thing I &lt;em&gt;don&apos;t&lt;/em&gt; think we should do is serialize access to the ClientSession because that would only provide the illusion that ClientSession is thread-safe. Better to raise an error to the user so that they can refactor the code with this session limitation in mind.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                                        </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="1050208">DRIVERS-2096</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </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_10951" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Driver Changes</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10748"><![CDATA[Needed]]></customfieldvalue>

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