<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:01:09 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-4069] ConnectionPoolSettings.maxConnectionIdleTimeMS/maxConnectionLifeTimeMS uses a non-monotonic timer</title>
                <link>https://jira.mongodb.org/browse/JAVA-4069</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;h2&gt;&lt;a name=&quot;Generalproblemexplanation&quot;&gt;&lt;/a&gt;General problem explanation&lt;/h2&gt;
&lt;p&gt;&lt;tt&gt;System.currentTimeMillis&lt;/tt&gt; represents a wall-clock time and therefore is not monotonic, i.e., it is allowed to go backwards: return &lt;tt&gt;t1&lt;/tt&gt; and after that (in the happens-before order) return &lt;tt&gt;t2 &amp;lt; t1&lt;/tt&gt;. While the lack of monotonicity is not explicitly expressed in the method specification, the fact that it returns wall-clock time and one can set machine time to a past instant (NTP implementations may also do that) implies the lack of monotonicity. As a result, naive attempts to calculate, e.g. timeout expiration, may fail: the expression &lt;tt&gt;(currentTime = System.currentTimeMillis()) - startTime &amp;gt; timeout&lt;/tt&gt;, where &lt;tt&gt;timeout&lt;/tt&gt; is 1000 ms may evaluate to &lt;tt&gt;false&lt;/tt&gt; for about an hour if the machine time is shifted back 1 hour, which misses the timeout for no good reason.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;System.nanoTime&lt;/tt&gt; on the other hand does not represent a wall-clock time (this is explicitly expressed in the specification) and is explicitly allowed to be used for measuring elapsed time.&lt;/p&gt;

&lt;p&gt;The Go standard library tries to prevent users from using a non-monotonic timer when measuring elapsed time by hiding both timers behind a single API: &lt;a href=&quot;https://golang.org/pkg/time/#hdr-Monotonic_Clocks&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://golang.org/pkg/time/#hdr-Monotonic_Clocks&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;&lt;a name=&quot;Specificproblem&quot;&gt;&lt;/a&gt;Specific problem&lt;/h2&gt;
&lt;h3&gt;&lt;a name=&quot;Relevantplacesinthecodebase&quot;&gt;&lt;/a&gt;Relevant places in the codebase&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/91e670f86303121c7afe68145d3ca5d341079506/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java#L357&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/blob/91e670f86303121c7afe68145d3ca5d341079506/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java#L357&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/91e670f86303121c7afe68145d3ca5d341079506/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java#L357&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/blob/91e670f86303121c7afe68145d3ca5d341079506/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java#L357&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/91e670f86303121c7afe68145d3ca5d341079506/driver-core/src/main/com/mongodb/internal/connection/UsageTrackingInternalConnection.java#L52&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/blob/91e670f86303121c7afe68145d3ca5d341079506/driver-core/src/main/com/mongodb/internal/connection/UsageTrackingInternalConnection.java#L52&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/91e670f86303121c7afe68145d3ca5d341079506/driver-core/src/main/com/mongodb/internal/connection/UsageTrackingInternalConnection.java#L95&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/blob/91e670f86303121c7afe68145d3ca5d341079506/driver-core/src/main/com/mongodb/internal/connection/UsageTrackingInternalConnection.java#L95&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;...&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;&lt;a name=&quot;Proposedsolution&quot;&gt;&lt;/a&gt;Proposed solution&lt;/h3&gt;
&lt;p&gt;&lt;tt&gt;UsageTrackingInternalConnection&lt;/tt&gt; does not need to track wall-clock time in &lt;tt&gt;openedAt&lt;/tt&gt;/&lt;tt&gt;lastUsedAt&lt;/tt&gt;. We can and should use &lt;tt&gt;System.nanoTime&lt;/tt&gt; to detect if &lt;tt&gt;maxConnectionIdleTimeMS&lt;/tt&gt;/&lt;tt&gt;maxConnectionLifeTimeMS&lt;/tt&gt; is exceeded.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1650402">JAVA-4069</key>
            <summary>ConnectionPoolSettings.maxConnectionIdleTimeMS/maxConnectionLifeTimeMS uses a non-monotonic timer</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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>Tue, 16 Mar 2021 19:17:42 +0000</created>
                <updated>Wed, 30 Mar 2022 23:07:14 +0000</updated>
                                            <version>4.3.0</version>
                                                    <component>Connection Management</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                    <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="1650408">JAVA-4070</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1650416">JAVA-4071</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1650423">JAVA-4072</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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hyky0v:</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>