<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:55:03 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-1613] Race condition on DBPort usage during write commands</title>
                <link>https://jira.mongodb.org/browse/JAVA-1613</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;A &lt;tt&gt;DBPort&lt;/tt&gt; maintains a &lt;tt&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/r2.13.0-rc1/src/main/com/mongodb/DBPort.java#L447&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;usageCount&lt;/a&gt;&lt;/tt&gt; which is incremented upon each usage of a &lt;tt&gt;DBPort&lt;/tt&gt;. In the case of an UNACKNOWLEDGED write, this &lt;tt&gt;usageCount&lt;/tt&gt; is utilized by &lt;tt&gt;WriteResult&lt;/tt&gt; to indicate when a subsequent call to &lt;tt&gt;getLastError()&lt;/tt&gt; is unsafe because its &lt;tt&gt;DBPort&lt;/tt&gt; has already been checked out and used by another thread. (To be fair, a deprecated pattern as of 2.13.0.)&lt;/p&gt;

&lt;p&gt;The race is that while non-write command operations using &lt;tt&gt;DBPort.say()&lt;/tt&gt; and &lt;tt&gt;DBPort.call()&lt;/tt&gt; &lt;em&gt;do&lt;/em&gt; ensure the &lt;tt&gt;usageCount&lt;/tt&gt; is safely incremented, write commands go through &lt;tt&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/r2.13.0-rc1/src/main/com/mongodb/DBTCPConnector.java#L204-L220&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;DBTCPConnector&lt;/a&gt;&lt;/tt&gt; and do &lt;em&gt;not&lt;/em&gt; increment this counter. &lt;/p&gt;

&lt;p&gt;Therefore it&apos;s possible that a write command on one thread may end up sharing a &lt;tt&gt;DBPort&lt;/tt&gt; for a &lt;tt&gt;getLastError()&lt;/tt&gt; call on another thread, resulting in undefined behavior.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Available Workaround&lt;/b&gt;&lt;br/&gt;
Use ACKNOWLEDGED writes whenever a &lt;tt&gt;getLastError()&lt;/tt&gt; result is required, such as for a &lt;tt&gt;WriteResult.getUpsertedId()&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Credit: &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jeff.yemin&quot; class=&quot;user-hover&quot; rel=&quot;jeff.yemin&quot;&gt;jeff.yemin&lt;/a&gt; for analysis and discovery.&lt;/p&gt;</description>
                <environment></environment>
        <key id="177373">JAVA-1613</key>
            <summary>Race condition on DBPort usage during write commands</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="9">Done</resolution>
                                        <assignee username="jeff.yemin@mongodb.com">Jeffrey Yemin</assignee>
                                    <reporter username="john.morales@mongodb.com">John Morales</reporter>
                        <labels>
                    </labels>
                <created>Wed, 7 Jan 2015 15:16:48 +0000</created>
                <updated>Fri, 1 Apr 2016 15:42:44 +0000</updated>
                            <resolved>Wed, 7 Jan 2015 20:06:46 +0000</resolved>
                                    <version>2.12.0</version>
                                    <fixVersion>2.12.5</fixVersion>
                                    <component>Connection Management</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="799418" author="xgen-internal-githook" created="Wed, 7 Jan 2015 20:06:35 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;jyemin&apos;, u&apos;name&apos;: u&apos;Jeff Yemin&apos;, u&apos;email&apos;: u&apos;jeff.yemin@10gen.com&apos;}
&lt;p&gt;Message: Fixed race condition between threads attempting to get the result of an unacknowledged write after the fact and threads attempting to do write commands.&lt;br/&gt;
The race was cause by a lack of synchronization on DPPort in the write command path, and a failure to update DBPort.usageCount on that path.&lt;/p&gt;

&lt;p&gt; &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-1613&quot; title=&quot;Race condition on DBPort usage during write commands&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-1613&quot;&gt;&lt;del&gt;JAVA-1613&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: 2.12.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/d64f5c8575ee9ab725e0d96737fda3c1e6b37634&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/d64f5c8575ee9ab725e0d96737fda3c1e6b37634&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="799415" author="xgen-internal-githook" created="Wed, 7 Jan 2015 20:06:29 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;jyemin&apos;, u&apos;name&apos;: u&apos;Jeff Yemin&apos;, u&apos;email&apos;: u&apos;jeff.yemin@10gen.com&apos;}
&lt;p&gt;Message: Fixed race condition between threads attempting to get the result of an unacknowledged write after the fact and threads attempting to do write commands.&lt;br/&gt;
The race was cause by a lack of synchronization on DPPort in the write command path, and a failure to update DBPort.usageCount on that path.&lt;/p&gt;

&lt;p&gt; &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-1613&quot; title=&quot;Race condition on DBPort usage during write commands&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-1613&quot;&gt;&lt;del&gt;JAVA-1613&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/befb3cf06aa2b3663acf13f84ac0d3a6d1cc4162&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/befb3cf06aa2b3663acf13f84ac0d3a6d1cc4162&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="180729">JAVA-1632</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hs58jr:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>155569</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="351">Java Sprint 12</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>