<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 04:28:52 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>[SERVER-32007] ExpressionDateFromString::evaluate() is not thread safe</title>
                <link>https://jira.mongodb.org/browse/SERVER-32007</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;In general, aggregation expressions are owned by a single thread responsible for executing the aggregate command. However, this is not the case for a &lt;a href=&quot;https://docs.mongodb.com/master/core/document-validation/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;document validator&lt;/a&gt; which uses &lt;a href=&quot;https://docs.mongodb.com/master/reference/operator/query/expr/#op._S_expr&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;$expr&lt;/a&gt;. A thread running a &lt;tt&gt;create&lt;/tt&gt; or &lt;tt&gt;collMod&lt;/tt&gt; commands sets up the validator. Subsequent writes to the collection can concurrently evaluate the aggregation expression, as part of &lt;tt&gt;$expr&lt;/tt&gt;. Note that this is the only the case for storage engines which support document-level concurrency; on MMAPv1, writes will take an exclusive collection lock and thus will not evaluate the &lt;tt&gt;$expr&lt;/tt&gt; concurrently.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;Expression::evaluate()&lt;/tt&gt; is marked as const and therefore is expected to be thread-safe, but &lt;tt&gt;ExpressionDateFromString&lt;/tt&gt;&apos;s evaluate implementation has a subtle data race. This expression holds a subexpression by &lt;tt&gt;boost::intrusive_ptr&lt;/tt&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo/blob/3b5249593ad3bdbc8799f6a2f80ba89568f7894a/src/mongo/db/pipeline/expression.h#L879&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/blob/3b5249593ad3bdbc8799f6a2f80ba89568f7894a/src/mongo/db/pipeline/expression.h#L879&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It passes this &lt;tt&gt;intrusive_ptr&lt;/tt&gt; by value to the &lt;tt&gt;makeTimeZone()&lt;/tt&gt; helper:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo/blob/3b5249593ad3bdbc8799f6a2f80ba89568f7894a/src/mongo/db/pipeline/expression.cpp#L1376&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/blob/3b5249593ad3bdbc8799f6a2f80ba89568f7894a/src/mongo/db/pipeline/expression.cpp#L1376&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This causes the &lt;tt&gt;intrusive_ptr&lt;/tt&gt; refcount to be incremented when this function is called, and decremented when the function returns. This increment/decrement pair amounts to mutating the object inside a const method, and it results in a data race. The &lt;tt&gt;Expression&lt;/tt&gt; class inherits from &lt;tt&gt;IntrusiveCounterUnsigned&lt;/tt&gt; in order to interface with &lt;tt&gt;instrusive_ptr&lt;/tt&gt;. &lt;tt&gt;IntrusiveCounterUnsigned&lt;/tt&gt; writes directly to an unsigned integer on increment and decrement:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo/blob/3b5249593ad3bdbc8799f6a2f80ba89568f7894a/src/mongo/util/intrusive_counter.h#L86&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/blob/3b5249593ad3bdbc8799f6a2f80ba89568f7894a/src/mongo/util/intrusive_counter.h#L86&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is in contrast to our &lt;tt&gt;RefCountable&lt;/tt&gt; class, whose refcount is an &lt;tt&gt;AtomicUInt32&lt;/tt&gt;.&lt;/p&gt;</description>
                <environment></environment>
        <key id="460004">SERVER-32007</key>
            <summary>ExpressionDateFromString::evaluate() is not thread safe</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</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="13201">Fixed</resolution>
                                        <assignee username="david.storch@mongodb.com">David Storch</assignee>
                                    <reporter username="david.storch@mongodb.com">David Storch</reporter>
                        <labels>
                    </labels>
                <created>Thu, 16 Nov 2017 22:06:03 +0000</created>
                <updated>Mon, 30 Oct 2023 23:10:27 +0000</updated>
                            <resolved>Fri, 17 Nov 2017 20:19:00 +0000</resolved>
                                    <version>3.6.0-rc4</version>
                                    <fixVersion>3.6.0-rc5</fixVersion>
                    <fixVersion>3.7.1</fixVersion>
                                    <component>Aggregation Framework</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1729280" author="xgen-internal-githook" created="Fri, 17 Nov 2017 20:31:21 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;David Storch&apos;, &apos;username&apos;: &apos;dstorch&apos;, &apos;email&apos;: &apos;david.storch@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-32007&quot; title=&quot;ExpressionDateFromString::evaluate() is not thread safe&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-32007&quot;&gt;&lt;del&gt;SERVER-32007&lt;/del&gt;&lt;/a&gt; Avoid unnecessary intrusive_ptr&amp;lt;Expression&amp;gt; copies in time expression evaluation.&lt;/p&gt;

&lt;p&gt;(cherry picked from commit 8e06e18365f4efe772c924fa377eaaa0f1ddd219)&lt;br/&gt;
Branch: v3.6&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/a7104648fa1d9b020ba7e4d82dffb96caa681a6c&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/a7104648fa1d9b020ba7e4d82dffb96caa681a6c&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1729279" author="xgen-internal-githook" created="Fri, 17 Nov 2017 20:31:19 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;David Storch&apos;, &apos;username&apos;: &apos;dstorch&apos;, &apos;email&apos;: &apos;david.storch@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-32007&quot; title=&quot;ExpressionDateFromString::evaluate() is not thread safe&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-32007&quot;&gt;&lt;del&gt;SERVER-32007&lt;/del&gt;&lt;/a&gt; Make evaluation of time-related agg expressions thread safe.&lt;/p&gt;

&lt;p&gt;(cherry picked from commit 411853747b6c5ee4e6d0f5d8ef063514e54d7ee0)&lt;br/&gt;
Branch: v3.6&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/360798e804b12983519c600a9e0b43d066ba8a4d&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/360798e804b12983519c600a9e0b43d066ba8a4d&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1729263" author="xgen-internal-githook" created="Fri, 17 Nov 2017 20:17:50 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;David Storch&apos;, &apos;username&apos;: &apos;dstorch&apos;, &apos;email&apos;: &apos;david.storch@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-32007&quot; title=&quot;ExpressionDateFromString::evaluate() is not thread safe&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-32007&quot;&gt;&lt;del&gt;SERVER-32007&lt;/del&gt;&lt;/a&gt; Avoid unnecessary intrusive_ptr&amp;lt;Expression&amp;gt; copies in time expression evaluation.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/8e06e18365f4efe772c924fa377eaaa0f1ddd219&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/8e06e18365f4efe772c924fa377eaaa0f1ddd219&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1729262" author="xgen-internal-githook" created="Fri, 17 Nov 2017 20:17:49 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;David Storch&apos;, &apos;username&apos;: &apos;dstorch&apos;, &apos;email&apos;: &apos;david.storch@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-32007&quot; title=&quot;ExpressionDateFromString::evaluate() is not thread safe&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-32007&quot;&gt;&lt;del&gt;SERVER-32007&lt;/del&gt;&lt;/a&gt; Make evaluation of time-related agg expressions thread safe.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/411853747b6c5ee4e6d0f5d8ef063514e54d7ee0&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/411853747b6c5ee4e6d0f5d8ef063514e54d7ee0&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1728328" author="david.storch" created="Thu, 16 Nov 2017 22:19:20 +0000"  >&lt;p&gt;This bug has been observed to cause a crash for &lt;tt&gt;ExpressionDateFromString&lt;/tt&gt; in our continuous integration system. It affects all of the 3.6 release candidates, though since &lt;tt&gt;$expr&lt;/tt&gt; and &lt;tt&gt;ExpressionDateFromString&lt;/tt&gt; are new, it does not affect old branches. The crash is likely a result of the data race causing the &lt;tt&gt;Expression&lt;/tt&gt; to be de-allocated when there is still an outstanding reference.&lt;/p&gt;

&lt;p&gt;It appears from the code that this affects other expressions, not just &lt;tt&gt;ExpressionDateFromString&lt;/tt&gt;. At the very least, all of the &lt;tt&gt;evaluate()&lt;/tt&gt; methods that call &lt;tt&gt;makeTimeZone()&lt;/tt&gt; are likely to be affected. It&apos;s possible that there are other &lt;tt&gt;Expression::evaluate()&lt;/tt&gt; implementations that are subtly non-const due to writes to the &lt;tt&gt;intrusive_ptr&lt;/tt&gt; refcount. Any such expression falls under the purview of this ticket as well.&lt;/p&gt;

&lt;p&gt;Finally, we should investigate whether there is a similar problem affecting any of the features which can persist query expressions:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Partial indexes.&lt;/li&gt;
	&lt;li&gt;Read-only non-materialized views.&lt;/li&gt;
&lt;/ul&gt;
</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10420">
                    <name>Backports</name>
                                            <outwardlinks description="backported by">
                                                        </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                                                <inwardlinks description="is depended on by">
                                                        </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>5.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18555" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname># of Sprints</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1.0</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_12450" key="com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes">
                        <customfieldname>Backport Requested</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="15141"><![CDATA[v3.6]]></customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Fri, 17 Nov 2017 20:17:49 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        6 years, 12 weeks, 5 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></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_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>luke.bonanomi@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            6 years, 12 weeks, 5 days ago
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_16465" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Linked BF Score</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0.0</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10026"><![CDATA[ALL]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>david.storch@mongodb.com</customfieldvalue>
            <customfieldvalue>xgen-internal-githook</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|htk7rz:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|htbx7z:</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>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="1979">Query 2017-12-04</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|htjtvr:</customfieldvalue>

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