<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:01:46 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-4316] The background thread should be able to hand over a new connection to a thread that is blocked by the max connecting limit</title>
                <link>https://jira.mongodb.org/browse/JAVA-4316</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Section &lt;a href=&quot;https://github.com/mongodb/specifications/blob/cfe5b5b2450948f1cfae07dcc780602b8b738a22/source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst#checking-out-a-connection&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;&quot;Checking Out a Connection&quot;&lt;/a&gt; in the CMAP specification says:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;the pool MUST wait to service the request until ... or until a Connection becomes available&lt;/p&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;the Pool MUST NOT service any newer checkOut requests before fulfilling the original one which could not be fulfilled&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Currently, &lt;tt&gt;DefaultConnectionPool.OpenConcurrencyLimiter.acquirePermitOrGetAvailableOpenedConnection&lt;/tt&gt; uses a hand over mechanism to implement the above requirements: when a connection is checked in, threads waiting inside &lt;tt&gt;acquirePermitOrGetAvailableOpenedConnection&lt;/tt&gt; are signalled, and are allowed to grab checked in connections before any other thread has a chance to check them out. However, there is another mechanism that may result in available connections appearing in a pool: the background thread populating the pool based on the &lt;tt&gt;minSize&lt;/tt&gt;. Consider the following execution:&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;&lt;tt&gt;tB&lt;/tt&gt; is the background thread that is establishing a connection to satisfy &lt;tt&gt;minSize&lt;/tt&gt;.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;t1&lt;/tt&gt; is a thread that is establishing a connection to satisfy a checkout operation.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;t2&lt;/tt&gt; is a thread that is waiting for a permit to establish a connection to satisfy a checkout, because both permits are taken by &lt;tt&gt;tB&lt;/tt&gt; and &lt;tt&gt;t1&lt;/tt&gt;.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;tB&lt;/tt&gt; completes establishing a connection, &lt;tt&gt;t1&lt;/tt&gt; continues establishing.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;t2&lt;/tt&gt; can now either notice that there is a new connection available in the pool and check it out, or take the available permit and start establishing a new connection.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;According to the specification, &lt;tt&gt;t2&lt;/tt&gt; MUST be the one who gets the connection created by &lt;tt&gt;tB&lt;/tt&gt;, but currently it ignores that connection completely, because the background thread populating the pool does not check new connections in. Instead, populating uses the &lt;tt&gt;ConcurrentPool.ensureMinSize&lt;/tt&gt; method.&lt;/p&gt;

&lt;p&gt;I believe, the background thread (see &lt;tt&gt;DefaultConnectionPool.doMaintenance&lt;/tt&gt;) should be able to use &lt;tt&gt;DefaultConnectionPool.OpenConcurrencyLimiter.tryHandOverOrRelease&lt;/tt&gt; (with some modifications) in order to hand over new connections similarly to how this happens in &lt;tt&gt;DefaultConnectionPool.PooledConnection.close&lt;/tt&gt;. If the background thread successfully hands over a connection, then &lt;tt&gt;ConcurrentPool.ensureMinSize&lt;/tt&gt; must not call &lt;tt&gt;ConcurrentPool.release&lt;/tt&gt; for such a connection.&lt;/p&gt;

&lt;p&gt;This scenario and the way to fix it came to me while I was thinking about &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4288&quot; title=&quot;Allow configuration of MAX_CONNECTING on the connection pool after 4.3.x changes&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4288&quot;&gt;&lt;del&gt;JAVA-4288&lt;/del&gt;&lt;/a&gt;. Fixing this bug will not only make the driver more compliant with the specification, but also will help reducing checkout latencies in situations like that in &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4288&quot; title=&quot;Allow configuration of MAX_CONNECTING on the connection pool after 4.3.x changes&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4288&quot;&gt;&lt;del&gt;JAVA-4288&lt;/del&gt;&lt;/a&gt;. However, on its own, it is unlikely to resolve &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4288&quot; title=&quot;Allow configuration of MAX_CONNECTING on the connection pool after 4.3.x changes&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4288&quot;&gt;&lt;del&gt;JAVA-4288&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1884794">JAVA-4316</key>
            <summary>The background thread should be able to hand over a new connection to a thread that is blocked by the max connecting limit</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="valentin.kovalenko@mongodb.com">Valentin Kavalenka</assignee>
                                    <reporter username="valentin.kovalenko@mongodb.com">Valentin Kavalenka</reporter>
                        <labels>
                    </labels>
                <created>Mon, 27 Sep 2021 20:20:40 +0000</created>
                <updated>Sat, 28 Oct 2023 11:21:01 +0000</updated>
                            <resolved>Fri, 15 Oct 2021 18:00:21 +0000</resolved>
                                    <version>4.3.0</version>
                                    <fixVersion>4.3.4</fixVersion>
                                    <component>Connection Management</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4127703" author="xgen-internal-githook" created="Fri, 15 Oct 2021 23:29:32 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Valentin Kovalenko&apos;, &apos;email&apos;: &apos;valentin.kovalenko@mongodb.com&apos;, &apos;username&apos;: &apos;stIncMale&apos;}
&lt;p&gt;Message: Enable the background thread to hand over a newly opened connection to a thread that is blocked by the max connecting limit (#805)&lt;/p&gt;

&lt;p&gt;Backport &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4316&quot; title=&quot;The background thread should be able to hand over a new connection to a thread that is blocked by the max connecting limit&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4316&quot;&gt;&lt;del&gt;JAVA-4316&lt;/del&gt;&lt;/a&gt;, &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4346&quot; title=&quot;Add a CMAP test that verifies the background thread hands over connections to threads doing checkout&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4346&quot;&gt;&lt;del&gt;JAVA-4346&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: 4.3.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/1fb7ed33b96f99b222a675b20ee53148b08a9cad&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/1fb7ed33b96f99b222a675b20ee53148b08a9cad&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4126987" author="xgen-internal-githook" created="Fri, 15 Oct 2021 17:58:46 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Valentin Kovalenko&apos;, &apos;email&apos;: &apos;valentin.kovalenko@mongodb.com&apos;, &apos;username&apos;: &apos;stIncMale&apos;}
&lt;p&gt;Message: Enable the background thread to hand over a newly opened connection to a thread that is blocked by the max connecting limit (#799)&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4316&quot; title=&quot;The background thread should be able to hand over a new connection to a thread that is blocked by the max connecting limit&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4316&quot;&gt;&lt;del&gt;JAVA-4316&lt;/del&gt;&lt;/a&gt;, &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4346&quot; title=&quot;Add a CMAP test that verifies the background thread hands over connections to threads doing checkout&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4346&quot;&gt;&lt;del&gt;JAVA-4346&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/1459dba02430d92d837d1d605d672379a76afaac&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/1459dba02430d92d837d1d605d672379a76afaac&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10020">
                    <name>Gantt Dependency</name>
                                            <outwardlinks description="has to be done before">
                                        <issuelink>
            <issuekey id="1896931">JAVA-4346</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10520">
                    <name>Problem/Incident</name>
                                            <outwardlinks description="causes">
                                        <issuelink>
            <issuekey id="1896923">DRIVERS-1948</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is caused by">
                                        <issuelink>
            <issuekey id="1585341">JAVA-3927</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="1865741">JAVA-4288</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <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_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10257" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Documentation Changes</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="11861"><![CDATA[Not Needed]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>JAVA-3890</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_21553" key="com.atlassian.jira.plugin.system.customfieldtypes:labels">
                        <customfieldname>Quarter</customfieldname>
                        <customfieldvalues>
                                        <label>FY22Q4</label>
    
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr3mgv:</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>