<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 06:05: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>[SERVER-66303] Ensure ReplicaSetMonitorManager shuts down before ServiceContextTest resets the global context</title>
                <link>https://jira.mongodb.org/browse/SERVER-66303</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;The issue is that setGlobalServiceContext is not thread safe. getGlobalServiceContext is also written in a way that assumes that setGlobalServiceContext is only called once at the beginning when there is only a single thread of context. Cpp tests that repeatedly calls setGlobalServiceContext can run into race with setGlobalServiceContext setting the global variable to &lt;a href=&quot;https://github.com/mongodb/mongo/blob/924507bde170b07fc25bb994ab6b0ee852afcb53/src/mongo/db/service_context.cpp#L95&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;null&lt;/a&gt; and before the destructor of the previous service context gets run (which is right after the end of &lt;a href=&quot;https://github.com/mongodb/mongo/blob/924507bde170b07fc25bb994ab6b0ee852afcb53/src/mongo/db/service_context.cpp#L96&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;this scope&lt;/a&gt;). Since the set and get are not protected by mutex, threads owned by the old service context trying to call getGlobalServiceContext will be able to observe that glolbal context variable has been set to null even before it completely gets destroyed.&lt;/p&gt;

&lt;p&gt;One particular workaround for the cpp tests is to shutdown and join the threads that is known to access getGlobalServiceContext before calling setGlobalServiceContext or replace the getGlobalServiceContext calls with references to serviceContext and make sure that ServiceContext destructor joins all threads that can reference it.&lt;/p&gt;

&lt;p&gt;Original description:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The RSMM is a decoration on the ServiceContext. For any unit tests that inherit from ServiceContextTest and link in the RSM/RSMM, ServiceContext&apos;s destructor is called before the ReplicaSetMonitorManager&apos;s (because the RSMM&apos;s destructor is &lt;a href=&quot;https://github.com/mongodb/mongo/blob/cfeae227e247b505bb94ed0637dd19c6f0800d04/src/mongo/util/decoration_container.h#L131-L133&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;called as part of ~DecorationContainer&lt;/a&gt;, which is a &lt;a href=&quot;https://github.com/mongodb/mongo/blob/cfeae227e247b505bb94ed0637dd19c6f0800d04/src/mongo/util/decorable.h#L154&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;member of Decorable objects&lt;/a&gt;). The RSM uses the RSMM&apos;s executor, which is &lt;a href=&quot;https://github.com/mongodb/mongo/blob/cfeae227e247b505bb94ed0637dd19c6f0800d04/src/mongo/client/replica_set_monitor_manager.cpp#L307&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;shutdown in RSMM::shutdown()&lt;/a&gt;, which is &lt;a href=&quot;https://github.com/mongodb/mongo/blob/cfeae227e247b505bb94ed0637dd19c6f0800d04/src/mongo/client/replica_set_monitor_manager.cpp#L122&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;called from ~RSMM&lt;/a&gt;. So, its possible for a task still to exist on this executor, and run after the ServiceContext has been destroyed - if the task tries to grab the service context, the test will crash (as happened in the linked BF).&lt;/p&gt;

&lt;p&gt;We attempted to fix this by using ServiceContext::ConstructorActionRegisterer to declare a destructor to be called before the ServiceContext is destroyed, but the ServiceContext used in ServiceContextTest &lt;a href=&quot;https://github.com/mongodb/mongo/blob/cfeae227e247b505bb94ed0637dd19c6f0800d04/src/mongo/db/service_context_test_fixture.cpp#L52-L57&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;isn&apos;t constructed using UniqueServiceContext&lt;/a&gt;, so it won&apos;t get registered.&lt;/p&gt;

&lt;p&gt;You can repro the issue in the linked BF by placing a call to getGlobalServiceContext() in RSMM::shutdown() (and running the test that failed in the BF - tenant_migration_donor_service_test).&lt;/p&gt;&lt;/blockquote&gt;</description>
                <environment></environment>
        <key id="2041585">SERVER-66303</key>
            <summary>Ensure ReplicaSetMonitorManager shuts down before ServiceContextTest resets the global context</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="13201">Fixed</resolution>
                                        <assignee username="randolph@mongodb.com">Randolph Tan</assignee>
                                    <reporter username="janna.golden@mongodb.com">Janna Golden</reporter>
                        <labels>
                            <label>neweng</label>
                            <label>sharding-nyc-subteam1</label>
                    </labels>
                <created>Fri, 6 May 2022 20:18:21 +0000</created>
                <updated>Sun, 29 Oct 2023 21:38:29 +0000</updated>
                            <resolved>Wed, 29 Jun 2022 18:09:06 +0000</resolved>
                                                    <fixVersion>6.1.0-rc0</fixVersion>
                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="4648559" author="xgen-internal-githook" created="Wed, 29 Jun 2022 18:05:29 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Randolph Tan&apos;, &apos;email&apos;: &apos;randolph@10gen.com&apos;, &apos;username&apos;: &apos;renctan&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-66303&quot; title=&quot;Ensure ReplicaSetMonitorManager shuts down before ServiceContextTest resets the global context&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-66303&quot;&gt;&lt;del&gt;SERVER-66303&lt;/del&gt;&lt;/a&gt; Ensure ReplicaSetMonitorManager shuts down before ServiceContextTest resets the global context&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo/commit/cef61424315589689c9c764b798494268239340e&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/commit/cef61424315589689c9c764b798494268239340e&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4612990" author="max.hirschhorn@10gen.com" created="Mon, 13 Jun 2022 22:01:50 +0000"  >&lt;blockquote&gt;
&lt;p&gt;We attempted to fix this by using ServiceContext::ConstructorActionRegisterer to declare a destructor to be called before the ServiceContext is destroyed, but the ServiceContext used in ServiceContextTest &lt;a href=&quot;https://github.com/mongodb/mongo/blob/cfeae227e247b505bb94ed0637dd19c6f0800d04/src/mongo/db/service_context_test_fixture.cpp#L52-L57&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;isn&apos;t constructed using UniqueServiceContext&lt;/a&gt;, so it won&apos;t get registered.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;If the ServiceContext used by C++ unit tests isn&apos;t respecting its ConstructorActionRegisterer, then it seems like the C++ test environment isn&apos;t being faithful to a typical mongod environment. This seems like an issue which would extend beyond the ReplicaSetMonitorManager. We should see if that&apos;s the case and engage with the Service Arch team as needed.&lt;/p&gt;

&lt;p&gt;Otherwise, we should look into solutions which have perhaps have the TenantMigrationDonorServiceTest test fixture explicitly shut down the ReplicaSetMonitors it ended up starting as part of &lt;a href=&quot;https://github.com/mongodb/mongo/blob/e399422548621ca737903284e8b435c804bb8254/src/mongo/db/repl/tenant_migration_donor_service_test.cpp#L94&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;its tearDown() method&lt;/a&gt; (for example, &lt;a href=&quot;https://github.com/mongodb/mongo/blob/ecb33ce31cc9774969449634c58f497c63553594/src/mongo/client/dbclient_rs_test.cpp#L123&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;what dbclient&amp;#95;rs&amp;#95;test.cpp does&lt;/a&gt;).&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                                                <inwardlinks description="is depended on by">
                                                        </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="2075544">SERVER-67478</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18555" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname># of Sprints</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2.0</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>Mon, 13 Jun 2022 22:01:50 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        1 year, 32 weeks 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_17050" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Downstream Team Attention</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="16941"><![CDATA[Not Needed]]></customfieldvalue>

                        </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>
                            1 year, 32 weeks ago
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_16465" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Linked BF Score</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14.0</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hraf5z:c</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_22250" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Special Downgrade Instructions Required</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="23343"><![CDATA[Not Needed]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="5738">Sharding 2022-06-27</customfieldvalue>
    <customfieldvalue id="6343">Sharding 2022-07-11</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|i0tmlb:</customfieldvalue>

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