<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:01:23 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-4156] Connections and threads may stay active after calling `MongoClient.close`</title>
                <link>https://jira.mongodb.org/browse/JAVA-4156</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;When a &lt;tt&gt;MongoClient&lt;/tt&gt; is closed, it closes the underlying servers, which close underlying connection pools, which close pooled connections. However, because &lt;tt&gt;MongoClient&lt;/tt&gt; is allowed to be used concurrently (true for both synchronous and reactive API), it is possible to have ongoing operations concurrently with calling &lt;tt&gt;MongoClient.close&lt;/tt&gt;. Such connections may be blocked waiting for a response from the server, and may stay not terminated on the client-side until timeout happens or a response is received.&lt;/p&gt;

&lt;p&gt;In other words, &lt;tt&gt;MongoClient.close&lt;/tt&gt; is an asynchronous operation even for a synchronous API, and it does not provide a user with a way to learn when all resources were actually closed (reasoning similar to the one about connections may also be applicable to threads started by the client). A solution from the API standpoint would be to either block &lt;tt&gt;MongoClient.close&lt;/tt&gt; (make it synchronous) until resources are released, or return a &lt;tt&gt;CompletableFuture&lt;/tt&gt; (a composition of &lt;tt&gt;Future&lt;/tt&gt; which allows blocking and &lt;tt&gt;CompletionStage&lt;/tt&gt;, which allows building an asynchronous pipeline). Implementing this does not seem to be trivial&lt;sup&gt;1&lt;/sup&gt;. Maybe we can decide to just document our &lt;tt&gt;close&lt;/tt&gt; methods on public classes that have them with a note that the methods are asynchronous with no way to know when the requested operation completes.&lt;/p&gt;

&lt;p&gt;Internally, this situation causes test logs from different tests to be interlaid with each other even if each test creates a new client and closes it when it ends. It is useful to keep this in mind.&lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt; &lt;tt&gt;ExecutorService&lt;/tt&gt; allows waiting until all its threads terminate, but does not allow listening for that. As for connections, we would need to wait until all checked out connections are checked in and then report that the pool is closed. This can be further improved by closing checked out connections in the places where they are used: doing so reduces the time to stop the whole client, but would have to be done in too many places and would significantly complicate the existing code (I do not think this last improvement should ever be done).&lt;/p&gt;</description>
                <environment></environment>
        <key id="1714649">JAVA-4156</key>
            <summary>Connections and threads may stay active after calling `MongoClient.close`</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="valentin.kovalenko@mongodb.com">Valentin Kavalenka</reporter>
                        <labels>
                    </labels>
                <created>Thu, 13 May 2021 14:44:16 +0000</created>
                <updated>Wed, 30 Mar 2022 23:00:02 +0000</updated>
                                                                            <component>Connection Management</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                        <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|hyvbyv:</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>