<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:55 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-279] ObjectId could generate duplicate ids if used in different classloader</title>
                <link>https://jira.mongodb.org/browse/JAVA-279</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;ObjectId currently uses timestamp and a machine id obtained using network stuff and a third part obtained trying to get the &quot;name&quot; of the currently running JVM.&lt;/p&gt;

&lt;p&gt;These three elements will always return the same tuple, in the same second, for the same virtual machine (as long as the RuntimeMXBean is available).&lt;/p&gt;

&lt;p&gt;Unfortunately, it will return the same tuple if two different classloaders (say, two different webapps) are active in the same JVM.&lt;/p&gt;

&lt;p&gt;The fourth element, the progressive counter, is taken from a static variable, so it&apos;s relative to the single classloader, not the entire JVM.&lt;/p&gt;

&lt;p&gt;This means that ObjectId could create two identical IDs if called from two different webapps, when both webapps try to write during the same second. If this happens on the same collection, this will cause errors.&lt;/p&gt;

&lt;p&gt;It seems like a very rare situation, but unfortunately it seems like this happened to me a couple of times, cause I was experimenting on using MongoDB to collect informations from different webapps, some of them running on the same Tomcat instance, and all writing more or less at the same time a log message on the same collection of the same db. The log message was to log that they were starting.&lt;/p&gt;

&lt;p&gt;The collision happened while the counter was rather low (below 100), probably on the long run the different counters in different classloaders will tend to diverge, but it&apos;s still a matter of randomness.&lt;/p&gt;

&lt;p&gt;A simple solution could be to add (xor or whatever) the System.identitiyHashCode of the current classloader to the processPiece, considering that in the progressive counter is relative to the classloader and that in a multiple classloader setup (like a web server) the closest match for &quot;process context&quot; is actually the classloader.&lt;/p&gt;


</description>
                <environment>Any JVM, Any OS</environment>
        <key id="14841">JAVA-279</key>
            <summary>ObjectId could generate duplicate ids if used in different classloader</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="antoine">Antoine Girbal</assignee>
                                    <reporter username="simonegianni">Simone Gianni</reporter>
                        <labels>
                    </labels>
                <created>Tue, 22 Feb 2011 04:03:41 +0000</created>
                <updated>Thu, 17 Mar 2011 19:13:55 +0000</updated>
                            <resolved>Tue, 22 Feb 2011 23:22:32 +0000</resolved>
                                    <version>2.4</version>
                                    <fixVersion>2.5</fixVersion>
                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="24635" author="simonegianni" created="Thu, 24 Feb 2011 21:48:10 +0000"  >&lt;p&gt;Great, thanks Antoine!&lt;/p&gt;</comment>
                            <comment id="24497" author="auto" created="Wed, 23 Feb 2011 01:46:42 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;agirbal&apos;, u&apos;name&apos;: u&apos;agirbal&apos;, u&apos;email&apos;: u&apos;antoine@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-279&quot; title=&quot;ObjectId could generate duplicate ids if used in different classloader&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-279&quot;&gt;&lt;del&gt;JAVA-279&lt;/del&gt;&lt;/a&gt;: ObjectId could generate duplicate ids if used in different classloader&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/de72e9cc320e1f342a21f91e425ad5c1a413c673&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/de72e9cc320e1f342a21f91e425ad5c1a413c673&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="24480" author="antoine" created="Tue, 22 Feb 2011 23:22:25 +0000"  >&lt;p&gt;thanks for report, that is important to fix.&lt;br/&gt;
Implemented a fix where machine id is contructed as:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;2 byte: hardware id based on a hash of string. String is concatenation of NICs description&lt;/li&gt;
	&lt;li&gt;2 byte: process id based on a hash of string. String is concatenation of process number and class loader hashcode.&lt;/li&gt;
&lt;/ul&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|hrgivr:</customfieldvalue>

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