<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:14:21 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-2160] Single-threaded server selection may block for minHeartbeatFrequencyMS unnecessarily</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-2160</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;When &lt;tt&gt;mongoc_topology_select_server_id()&lt;/tt&gt; decides to scan the topology in single-threaded mode, it calculates &lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/blob/1.5.5/src/mongoc/mongoc-topology.c#L552&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;&quot;how soon are we allowed to scan?&quot;&lt;/a&gt; by adding &lt;tt&gt;minHeartbeatFrequencyMS&lt;/tt&gt; to the last scan time. This calculation occurs irrespective of whether any nodes will actually be scanned. For example, previous connection failures may result in all nodes being excluded from this scan due to &lt;tt&gt;cooldownMS&lt;/tt&gt;. Ideally, the loop should check if there will be nodes to scan before a possible sleep for &lt;tt&gt;minHeartbeatFrequencyMS&lt;/tt&gt; or call to &lt;tt&gt;_mongoc_topology_do_blocking_scan()&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Consider the case in &lt;a href=&quot;#592&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;mongodb/mongo-php-driver#592&lt;/a&gt;. A PHP worker with a newly created libmongoc client attempts to connect to a closed port on an accessible host, which fails immediately and leaves the node in the &quot;Unknown&quot; state. A subsequent requests to that worker will re-use the persisted libmongoc client and block until &lt;tt&gt;minHeartbeatFrequencyMS&lt;/tt&gt; has elapsed since the previous request&apos;s failure. In a high-concurrency environment, this means that each request will block for approximately &lt;tt&gt;minHeartbeatFrequencyMS&lt;/tt&gt; instead of failing early, despite any attempts to tweak &lt;tt&gt;serverSelectionTimeoutMS&lt;/tt&gt; (note: connection/socket timeouts aren&apos;t relevant here).&lt;/p&gt;

&lt;p&gt;The spec&apos;s pseudo-code for &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#scanning-order&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Scanning Order&lt;/a&gt; does not address &lt;tt&gt;minHeartbeatFrequencyMS&lt;/tt&gt;; however, it does refer to aborting early if there would be no nodes to scan, as is the case here.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;On a related note, there &lt;em&gt;is&lt;/em&gt; logic to abort early with a server selection failure if the calculated time would &lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/blob/1.5.5/src/mongoc/mongoc-topology.c#L556&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;exceed our server selection timeout&lt;/a&gt;, however, this logic does not apply in &lt;tt&gt;serverSelectionTryOnce&lt;/tt&gt; mode and it would not affect the scenario described in the linked PHP ticket.&lt;/p&gt;</description>
                <environment></environment>
        <key id="383619">CDRIVER-2160</key>
            <summary>Single-threaded server selection may block for minHeartbeatFrequencyMS unnecessarily</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="13201">Fixed</resolution>
                                        <assignee username="jesse@mongodb.com">A. Jesse Jiryu Davis</assignee>
                                    <reporter username="jmikola@mongodb.com">Jeremy Mikola</reporter>
                        <labels>
                    </labels>
                <created>Mon, 15 May 2017 17:30:49 +0000</created>
                <updated>Sat, 28 Oct 2023 11:30:41 +0000</updated>
                            <resolved>Wed, 14 Feb 2018 14:41:57 +0000</resolved>
                                    <version>1.5.5</version>
                                    <fixVersion>1.10.0</fixVersion>
                                    <component>libmongoc</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="1805496" author="xgen-internal-githook" created="Wed, 14 Feb 2018 14:41:11 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;email&apos;: &apos;jesse@mongodb.com&apos;, &apos;name&apos;: &apos;A. Jesse Jiryu Davis&apos;, &apos;username&apos;: &apos;ajdavis&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-2160&quot; title=&quot;Single-threaded server selection may block for minHeartbeatFrequencyMS unnecessarily&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-2160&quot;&gt;&lt;del&gt;CDRIVER-2160&lt;/del&gt;&lt;/a&gt; don&apos;t sleep if scanner isn&apos;t ready&lt;/p&gt;

&lt;p&gt;If we&apos;ve seen network errors trying to check all servers less than 5&lt;br/&gt;
seconds ago, then don&apos;t sleep minHeartbeatFrequencyMS (500ms) before&lt;br/&gt;
giving up on server selection; give up right away.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/277496fd3eed0f74c2aab4c4fea2a930309f2c34&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/277496fd3eed0f74c2aab4c4fea2a930309f2c34&lt;/a&gt;&lt;/p&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|hszle7:</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>