<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:19:23 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-3913] Reduce likelihood of colliding ObjectID random sequence</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-3913</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;ObjectID random values and the counter sequence is seeded from combining time, PID, and hostname as noted in the &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/objectid.rst#random-value&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;ObjectID specification&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The seed is generated in &lt;tt&gt;_bson_context_init_random&lt;/tt&gt; as an XOR of:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;current time in seconds.&lt;/li&gt;
	&lt;li&gt;current time in microseconds. (this is incorrectly documented as milliseconds)&lt;/li&gt;
	&lt;li&gt;PID&lt;/li&gt;
	&lt;li&gt;hostname&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jmikola&quot; class=&quot;user-hover&quot; rel=&quot;jmikola&quot;&gt;jmikola&lt;/a&gt; identified two possible problems with the current seed generation:&lt;br/&gt;
1. The PID is stored as a &lt;tt&gt;uint16_t&lt;/tt&gt;. This truncates PIDs exceeding the range of an &lt;tt&gt;uint16_t&lt;/tt&gt;.&lt;br/&gt;
2. Because time is a sequential, and the PID is likely sequential on most systems, the XOR logic may be susceptible to duplicate seeds in rare cases where the difference in PID equals the difference in microseconds.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;PID uint16_t truncation&lt;/b&gt;&lt;br/&gt;
&lt;tt&gt;_bson_getpid&lt;/tt&gt; currently returns a &lt;tt&gt;uint16_t&lt;/tt&gt;. The PID generated is truncated into a &lt;tt&gt;uint16_t&lt;/tt&gt;, which likely restricts the range of PIDs on many systems where the maximum number of processes exceeds &lt;tt&gt;2^16 =  65536&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Looking at the implementation of &lt;tt&gt;_bson_getpid&lt;/tt&gt;:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Windows uses the 32 bit DWORD returned by GetCurrentProcessId, XORing each 16 bit half.&lt;/li&gt;
	&lt;li&gt;Non-Windows casts the &lt;tt&gt;pid_t&lt;/tt&gt; directly as a uint16_t. Inspecting &lt;tt&gt;unistd.h&lt;/tt&gt; on macOS shows this to be a typedef of &lt;tt&gt;int32_t&lt;/tt&gt;, on 64 bit Ubuntu 18.04 &lt;tt&gt;pid_t&lt;/tt&gt; typedefs an &lt;tt&gt;int&lt;/tt&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The truncation of a signed wider integer type to a narrower unsigned type is likely undefined, and could run the risk of two different process IDs colliding.&lt;/p&gt;

&lt;p&gt;The value of &lt;tt&gt;_bson_getpid&lt;/tt&gt; is only used as part of the random seed in &lt;tt&gt;_bson_context_init_random&lt;/tt&gt;, which is already generated from an &lt;tt&gt;int&lt;/tt&gt;. Let&apos;s store this directly as a 32 bit integer type as input to the random seed if possible.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Duplicate seeds from sequential XORs&lt;/b&gt;&lt;br/&gt;
Consider the following scenario brought up by &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jmikola&quot; class=&quot;user-hover&quot; rel=&quot;jmikola&quot;&gt;jmikola&lt;/a&gt;:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;Process 30596 initializes at time 1614071145.568000&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;30596 ^ 1614071145 ^ 568000 = 1614551085&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;Process 30597 initializes at time 1614071145.568001&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;30597 ^ 1614071145 ^ 568001 = 1614551085&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;A plausible solution may be to bit shift before XORing.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Testing&lt;/b&gt;&lt;br/&gt;
If it is possible, let&apos;s make the process ID, time, and hostname configurable so we can unit test &lt;tt&gt;_bson_context_init_random&lt;/tt&gt;. Given the difficulty of investigating this behavior in user applications, as part of this ticket, I think we should test scenarios like sequential process IDs with times differing by one microsecond.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1632109">CDRIVER-3913</key>
            <summary>Reduce likelihood of colliding ObjectID random sequence</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="kevin.albertson@mongodb.com">Kevin Albertson</reporter>
                        <labels>
                    </labels>
                <created>Wed, 24 Feb 2021 14:01:54 +0000</created>
                <updated>Mon, 23 May 2022 19:05:52 +0000</updated>
                            <resolved>Mon, 23 May 2022 19:05:51 +0000</resolved>
                                                                                        <votes>1</votes>
                                    <watches>5</watches>
                                                                                                                    <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="1927619">CDRIVER-4231</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="1927619">CDRIVER-4231</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                                        </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                    <customfield id="customfield_13552" key="com.go2group.jira.plugin.crm:crm_generic_field">
                        <customfieldname>Case</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[[5002K00000rzvmEQAQ]]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                    <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|hr6jfb:</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>