<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:02:01 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-4417] Memory leak in AsynchronousTlsChannelGroup</title>
                <link>https://jira.mongodb.org/browse/JAVA-4417</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;We are observing a memory leak related to&#160;&lt;tt&gt;com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Driver version is 4.3.4&#160;&lt;/p&gt;

&lt;p&gt;Server is Azure CosmosDB using MongoDB Server version 4.0, server-side retries enabled, SSL enabled.&lt;/p&gt;

&lt;p&gt;Application is using spring-boot 2.4.5 and reactive stack.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;The leak starts after the following exception is thrown:&#160;&lt;/p&gt;

&lt;p&gt;{{java.nio.channels.ClosedChannelException&lt;br/&gt;
	at java.base/java.nio.channels.spi.AbstractSelectableChannel.register(Unknown Source)&lt;br/&gt;
	at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.registerPendingSockets(AsynchronousTlsChannelGroup.java:612)&lt;br/&gt;
	at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.loop(AsynchronousTlsChannelGroup.java:414)&lt;br/&gt;
	at java.base/java.lang.Thread.run(Unknown Source)}}&lt;/p&gt;

&lt;p&gt;The leak is in&#160;&lt;tt&gt;com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup#pendingRegistrations&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Pending registrations are accumulating and eventually causing OOM.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/348392/348392_heapdump.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;It seems that&#160;&lt;tt&gt;com.mongodb.connection.TlsChannelStreamFactoryFactory.TlsChannelStream#openAsync&lt;/tt&gt; will continue to create&#160;&lt;tt&gt;AsynchronousTlsChannel&lt;/tt&gt; instances addig new pending registrations even after the&#160;&lt;tt&gt;com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup#loop&lt;/tt&gt; was shut down.&lt;/p&gt;

&lt;p&gt;Not exactly clear what is triggering this behavior as we only observed it on one of our environments. It also needs decent time before it happens. Last time it took 2 days before it started.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;There are other exceptions thrown prior to this one but hours or days before so not necessarily related:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;java.lang.NullPointerException: Cannot invoke &quot;com.mongodb.internal.connection.tlschannel.impl.BufferHolder.prepare()&quot; because &quot;this.outEncrypted&quot; is null at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.wrapAndWrite(TlsChannelImpl.java:393) at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.write(TlsChannelImpl.java:384) at com.mongodb.internal.connection.tlschannel.ClientTlsChannel.write(ClientTlsChannel.java:184) at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.writeHandlingTasks(AsynchronousTlsChannelGroup.java:540) at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.doWrite(AsynchronousTlsChannelGroup.java:498) at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.lambda$processWrite$4(AsynchronousTlsChannelGroup.java:459) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source)&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Another one is:&#160;&lt;br/&gt;
&lt;tt&gt;error in operation&#160;java.lang.NullPointerException&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Most probably thrown from{{&#160;com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup#processWrite}}&lt;/p&gt;</description>
                <environment></environment>
        <key id="1939104">JAVA-4417</key>
            <summary>Memory leak in AsynchronousTlsChannelGroup</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="d4niel.imre@gmail.com">D&#225;niel Imre</reporter>
                        <labels>
                            <label>external-user</label>
                    </labels>
                <created>Tue, 30 Nov 2021 11:07:52 +0000</created>
                <updated>Sat, 28 Oct 2023 11:20:55 +0000</updated>
                            <resolved>Thu, 6 Jan 2022 16:17:29 +0000</resolved>
                                                    <fixVersion>4.4.1</fixVersion>
                                    <component>Reactive Streams</component>
                                        <votes>1</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="4278734" author="xgen-internal-githook" created="Thu, 6 Jan 2022 16:34:30 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Valentin Kovalenko&apos;, &apos;email&apos;: &apos;valentin.male.kovalenko@gmail.com&apos;, &apos;username&apos;: &apos;stIncMale&apos;}
&lt;p&gt;Message: Merge changes from tls-channel for race condition manifested when closing async sockets right after creation (#851)&lt;/p&gt;

&lt;p&gt;This is a backport of &lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/pull/848&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/pull/848&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4417&quot; title=&quot;Memory leak in AsynchronousTlsChannelGroup&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4417&quot;&gt;&lt;del&gt;JAVA-4417&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: 4.4.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/eec0eed9a3586fd423c07958b0dba0d48adb6f01&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/eec0eed9a3586fd423c07958b0dba0d48adb6f01&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4275452" author="xgen-internal-githook" created="Wed, 5 Jan 2022 01:50:16 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Valentin Kovalenko&apos;, &apos;email&apos;: &apos;valentin.male.kovalenko@gmail.com&apos;, &apos;username&apos;: &apos;stIncMale&apos;}
&lt;p&gt;Message: Merge changes from tls-channel for race condition manifested when closing async sockets right after creation (#848)&lt;/p&gt;

&lt;p&gt;See the bug report &lt;a href=&quot;https://github.com/marianobarrios/tls-channel/issues/34&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/marianobarrios/tls-channel/issues/34&lt;/a&gt;&lt;br/&gt;
and the two PRs from which the changes were manually merged:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/marianobarrios/tls-channel/pull/35/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/marianobarrios/tls-channel/pull/35/&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/marianobarrios/tls-channel/pull/36&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/marianobarrios/tls-channel/pull/36&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4417&quot; title=&quot;Memory leak in AsynchronousTlsChannelGroup&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4417&quot;&gt;&lt;del&gt;JAVA-4417&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/9ecb895f4aac814b2166b854811e8321bd99aa66&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/9ecb895f4aac814b2166b854811e8321bd99aa66&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4235888" author="JIRAUSER1258163" created="Wed, 8 Dec 2021 00:45:10 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=d4niel.imre%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;d4niel.imre@gmail.com&quot;&gt;d4niel.imre@gmail.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Just giving you a quick update. The problem stems from the &lt;a href=&quot;https://github.com/marianobarrios/tls-channel&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;tls-channel&lt;/a&gt; library that we &lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/tree/master/driver-core/src/main/com/mongodb/internal/connection/tlschannel&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;shade&lt;/a&gt; in the driver. I reported the &lt;a href=&quot;https://github.com/marianobarrios/tls-channel/issues/34&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;issue&lt;/a&gt; in detail and proposed a solution. Will see what the author thinks about it.&lt;/p&gt;</comment>
                            <comment id="4225313" author="jeff.yemin" created="Wed, 1 Dec 2021 20:26:49 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=d4niel.imre%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;d4niel.imre@gmail.com&quot;&gt;d4niel.imre@gmail.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thanks for letting us know.  We will look into it and get back to you with any further questions.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="348392" name="heapdump.png" size="60447" author="d4niel.imre@gmail.com" created="Tue, 30 Nov 2021 10:51:42 +0000"/>
                    </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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr3mrz:</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>