<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:00:48 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-3927] Rate limit new connection creations (maxConnecting)</title>
                <link>https://jira.mongodb.org/browse/JAVA-3927</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description></description>
                <environment></environment>
        <key id="1585341">JAVA-3927</key>
            <summary>Rate limit new connection creations (maxConnecting)</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</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="esha.bhargava@mongodb.com">Esha Bhargava</reporter>
                        <labels>
                    </labels>
                <created>Sun, 10 Jan 2021 23:16:00 +0000</created>
                <updated>Sat, 28 Oct 2023 11:21:29 +0000</updated>
                            <resolved>Wed, 14 Apr 2021 18:55:22 +0000</resolved>
                                                    <fixVersion>4.3.0</fixVersion>
                                    <component>Connection Management</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="5133730" author="JIRAUSER1272462" created="Mon, 23 Jan 2023 17:17:18 +0000"  >&lt;p&gt;Hi Ashni,&lt;/p&gt;

&lt;p&gt;Thanks for the reply. I have created new ticket as below,&lt;br/&gt;
&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4851&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/JAVA-4851&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks,&lt;/p&gt;

&lt;p&gt;Senthil&lt;/p&gt;</comment>
                            <comment id="5117850" author="JIRAUSER1268547" created="Tue, 17 Jan 2023 15:55:45 +0000"  >&lt;p&gt;Hi Senthil, I chatted with the team about this one. Regarding the commit that you linked about deadlock, we don&apos;t believe that it is applicable specifically to the 3.12.9 driver version.&lt;/p&gt;

&lt;p&gt;Regarding the similar issue that you mention, I think it would be best to file a new ticket on this project with your driver/server version details and any additional information that you think might be helpful for us as we investigate.&lt;/p&gt;</comment>
                            <comment id="5110842" author="JIRAUSER1272462" created="Fri, 13 Jan 2023 04:56:26 +0000"  >&lt;p&gt;Hi Ashni,&lt;/p&gt;

&lt;p&gt;It would be helpful us, if you provide an update on the above query.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;/p&gt;

&lt;p&gt;Senthil&lt;/p&gt;</comment>
                            <comment id="5094939" author="JIRAUSER1272462" created="Fri, 6 Jan 2023 06:11:41 +0000"  >&lt;p&gt;Hi Ashni,&lt;/p&gt;

&lt;p&gt;Thanks for the quick response. My query is, whether the reported issue is applicable for 3.12.9?&lt;br/&gt;
Because, we are using 3.12.9 in our product, and we are seeing similar issue. So, if this is applicable, do we need to backport the fix in 3.12.9?&lt;/p&gt;

&lt;p&gt;Thanks,&lt;/p&gt;

&lt;p&gt;Senthil&lt;/p&gt;</comment>
                            <comment id="5093156" author="JIRAUSER1268547" created="Thu, 5 Jan 2023 15:57:37 +0000"  >&lt;p&gt;Hi Senthil, I believe this is available in 4.3.0 and later.&lt;/p&gt;</comment>
                            <comment id="5091994" author="JIRAUSER1272462" created="Thu, 5 Jan 2023 05:54:39 +0000"  >&lt;p&gt;Hi All,&lt;/p&gt;

&lt;p&gt;Issue fixed as part of the below is applicable for 3.12.9 version?&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/73e30857eed2f1d02ff7e9a6e5028d557a1cf4cf&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/73e30857eed2f1d02ff7e9a6e5028d557a1cf4cf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Can someone help on this.&lt;/p&gt;</comment>
                            <comment id="3867202" author="xgen-internal-githook" created="Tue, 8 Jun 2021 19:30:21 +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:  Refactor `DefaultConnectionPool` to use single worker thread when checking out asynchronously (#722)&lt;/p&gt;

&lt;p&gt;When implementing &lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/73e30857eed2f1d02ff7e9a6e5028d557a1cf4cf&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/73e30857eed2f1d02ff7e9a6e5028d557a1cf4cf&lt;/a&gt;&lt;br/&gt;
I correctly explained the deadlock situation:&lt;br/&gt;
1) An async task that created a non-open connection and tries to open it (let us call it an &quot;open task&quot;)&lt;br/&gt;
may block another async task that tries to create a connection (let us call it a &quot;get task&quot;)&lt;br/&gt;
if `maxSize` is reached.&lt;br/&gt;
2) If both tasks are submitted to the same queue such that the get task is ahead of the open task, then&lt;br/&gt;
such a get task naturally blocks the open task while being blocked by the open task.&lt;br/&gt;
but failed to optimally fix it.&lt;/p&gt;

&lt;p&gt;The solution to the problem I used is to submit tasks to different queues, which,&lt;br/&gt;
because both tasks are blocking, required introducing one more async worker thread.&lt;/p&gt;

&lt;p&gt;However, there is another approach to solving the deadlock problem,&lt;br/&gt;
which did not occur to me at that time: prevent the get task to be ahead of the open task&lt;br/&gt;
in the queue. This may happen due to the optimization in the `getAsync` method, which&lt;br/&gt;
tries to check out synchronously if an open connection is available,&lt;br/&gt;
i.e., if checking it out requires no blocking. It is a nice optimization that I&lt;br/&gt;
tried to preserve (it was there before my changes) when implemented &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3927&quot; title=&quot;Rate limit new connection creations (maxConnecting)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3927&quot;&gt;&lt;del&gt;JAVA-3927&lt;/del&gt;&lt;/a&gt;.&lt;br/&gt;
However, this optimization opens up opportunities for a get task being blocked&lt;br/&gt;
by an open task to be ordered ahead of the open task in the queue.&lt;/p&gt;

&lt;p&gt;If I realized that previously, I would have sacrificed this optimization&lt;br/&gt;
to eliminate the deadlock instead of introducing another queue and a thread.&lt;br/&gt;
Fortunately, the it occurred to me now.&lt;/p&gt;

&lt;p&gt;This change also fixes reactive `MainTransactionsTest` runner&lt;br/&gt;
so that the `abort.json`: &quot;implicit abort&quot; test succeeds.&lt;br/&gt;
This test expects command_started_event for the abortTransaction command, which is sent&lt;br/&gt;
as a result of closing the session used by the test. The close method is asynchronous and&lt;br/&gt;
the test must wait for its completion.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4146&quot; title=&quot;Fix timeout handling in `DefaultConnectionPool.getAsync`&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4146&quot;&gt;&lt;del&gt;JAVA-4146&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/6ab9ce6462f5cc1a994e9a829a1a7c27ecb2c546&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/6ab9ce6462f5cc1a994e9a829a1a7c27ecb2c546&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3750947" author="xgen-internal-githook" created="Sun, 2 May 2021 00:18:34 +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: Simplify `DefaultConnectionPool.OpenConcurrencyLimiter.tryLock` (#702)&lt;/p&gt;

&lt;p&gt;When locking for the purpose of using the wait/signal approach,&lt;br/&gt;
one does not have to account the time spent acquiring the lock&lt;br/&gt;
towards the timeout. While doing so may reduce the&lt;br/&gt;
non-deterministic duration by which a timeout is exceeded&lt;br/&gt;
by any implementation of a timeout, such overtime is usually negligible,&lt;br/&gt;
unless the lock is highly contended and/or checking the condition&lt;br/&gt;
before starting to wait is time-consuming.&lt;/p&gt;

&lt;p&gt;The Java SE example for `java.util.concurrent.locks.Condition.awaitNanos`&lt;br/&gt;
ignores the time spent acquiring the lock. Doing so potentially reduces&lt;br/&gt;
responsiveness to timeouts, but does not&lt;br/&gt;
affect other performance characteristics, so I believe such simplification&lt;br/&gt;
is worth it and I should have taken this path initially.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3927&quot; title=&quot;Rate limit new connection creations (maxConnecting)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3927&quot;&gt;&lt;del&gt;JAVA-3927&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/ddefdb0cc29541f82d507318ef7f94ec03efcd39&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/ddefdb0cc29541f82d507318ef7f94ec03efcd39&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3750869" author="xgen-internal-githook" created="Sat, 1 May 2021 16:18:33 +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: Fix deadlock and couple more problems in `DefaultConnectionPool` (#699)&lt;/p&gt;

&lt;p&gt;This commit fixes three problems in `DefaultConnectionPool`/`ConcurrentPool`:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;deadlock in `DefaultConnectionPool`;&lt;/li&gt;
	&lt;li&gt;unnecessary and harmful removal from `OpenConcurrencyLimiter.desiredConnectionSlots`;&lt;/li&gt;
	&lt;li&gt;double release in `DefaultConnectionPool`/`ConcurrentPool`.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;Deadlock in `DefaultConnectionPool`&lt;/p&gt;

&lt;p&gt;a) Before introducing OpenConcurrencyLimiter, &quot;AsyncGetter&quot; thread was used only&lt;br/&gt;
to do blocking `ConcurrentPool.get`.&lt;br/&gt;
b) After, I started to additionally use &quot;AsyncGetter&quot; to do&lt;br/&gt;
blocking `OpenConcurrencyLimiter.waitUntilOpenPermitAvailable`.&lt;/p&gt;

&lt;p&gt;As a result, we may have a thread that gets the last connection (`maxSize` is reached)&lt;br/&gt;
from `ConcurrentPool` and submits `waitUntilOpenPermitAvailable` to &quot;AsyncGetter&quot;.&lt;br/&gt;
Concurrently with this happening, the &quot;AsyncGetter&quot; tries to get from `ConcurrentPool`&lt;br/&gt;
and is blocked because there are no more connections available. In such an execution,&lt;br/&gt;
`waitUntilOpenPermitAvailable` cannot be completed by &quot;AsyncGetter&quot; because&lt;br/&gt;
&quot;AsyncGetter&quot; is blocked doing a different task, which itself cannot be completed.&lt;/p&gt;

&lt;p&gt;A solution is to do `ConcurrentPool.get` and `waitUntilOpenPermitAvailable`&lt;br/&gt;
in different threads. This way these two different kinds of tasks&lt;br/&gt;
will not block each other by waiting in the same queue to be done by a single thread.&lt;/p&gt;


&lt;p&gt;Potential unnecessary and harmful removal from `OpenConcurrencyLimiter.desiredConnectionSlots`&lt;/p&gt;

&lt;p&gt;If `acquirePermitOrGetAvailableOpenedConnection` is called with `true` as `tryGetAvailable`,&lt;br/&gt;
and `getPooledConnectionImmediately` throws an exception,&lt;br/&gt;
then `expressDesireToGetAvailableConnection` is not called&lt;br/&gt;
but `giveUpOnTryingToGetAvailableConnection` is still called, which is incorrect.&lt;/p&gt;


&lt;p&gt;Double release in `DefaultConnectionPool`/`ConcurrentPool`&lt;/p&gt;

&lt;p&gt;On one hand `ConcurrentPool.ensureMinSize` tries to not require the caller to do&lt;br/&gt;
what can be done by the method itself, e.g., it releases the connection to the pool itself.&lt;br/&gt;
On the other hand, always releasing in `ensureMinSize` may lead&lt;br/&gt;
to releasing a permit for the same connection twice, thus not respecting the `maxSize`.&lt;/p&gt;

&lt;p&gt;It is not easy (requires an additional knob and logic)&lt;br/&gt;
to prevent the caller (`DefaultConnectionPool`) from releasing a connection&lt;br/&gt;
when initialization fails. It is, therefore, seems better to mandate that the caller&lt;br/&gt;
releases a connection if initialization fails.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3927&quot; title=&quot;Rate limit new connection creations (maxConnecting)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3927&quot;&gt;&lt;del&gt;JAVA-3927&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/73e30857eed2f1d02ff7e9a6e5028d557a1cf4cf&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/73e30857eed2f1d02ff7e9a6e5028d557a1cf4cf&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3718903" author="xgen-internal-githook" created="Wed, 14 Apr 2021 18:53: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: Rate limit new connection creations (maxConnecting) (#685)&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3927&quot; title=&quot;Rate limit new connection creations (maxConnecting)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3927&quot;&gt;&lt;del&gt;JAVA-3927&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/ead0357131c1c0baa364656b07c91f2c789918e3&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/ead0357131c1c0baa364656b07c91f2c789918e3&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                                        </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10520">
                    <name>Problem/Incident</name>
                                            <outwardlinks description="causes">
                                        <issuelink>
            <issuekey id="1884794">JAVA-4316</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1970663">JAVA-4451</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1680527">JAVA-4104</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1707135">JAVA-4146</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1970791">JAVA-4452</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1884816">JAVA-4318</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="1919386">JAVA-4390</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|hr69sn:</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>