<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:59 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-310] Driver reconnect does not detect network IP changes.</title>
                <link>https://jira.mongodb.org/browse/JAVA-310</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Our application runs on machines that are sometimes moved between networks or has its IP address changed.&lt;/p&gt;

&lt;p&gt;When we create the Mongo instance it is done using the &quot;localhost&quot; host for the Mongo server.  The Mongo driver appears to always resolve to an IP on the local subnet.  &quot;192.168.0.10&quot; for example.   When the network chances however, our applications starts failing with errors like the following because it can no longer connect:&lt;/p&gt;

&lt;p&gt;jvm 1    | java.io.IOException: couldn&apos;t connect to &lt;span class=&quot;error&quot;&gt;&amp;#91;io/192.168.0.10:27017&amp;#93;&lt;/span&gt; bc:java.net.ConnectException: Operation timed out&lt;br/&gt;
jvm 1    | 	at com.mongodb.DBPort._open(DBPort.java:205)&lt;br/&gt;
jvm 1    | 	at com.mongodb.DBPort.go(DBPort.java:94)&lt;br/&gt;
jvm 1    | 	at com.mongodb.DBPort.go(DBPort.java:75)&lt;br/&gt;
jvm 1    | 	at com.mongodb.DBPort.call(DBPort.java:65)&lt;br/&gt;
jvm 1    | 	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:215)&lt;br/&gt;
jvm 1    | 	at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)&lt;br/&gt;
jvm 1    | 	at com.mongodb.DBCursor._check(DBCursor.java:354)&lt;br/&gt;
jvm 1    | 	at com.mongodb.DBCursor._hasNext(DBCursor.java:484)&lt;br/&gt;
jvm 1    | 	at com.mongodb.DBCursor.hasNext(DBCursor.java:509)&lt;br/&gt;
jvm 1    | 	at com.mongodb.jdbc.MongoResultSet.next(MongoResultSet.java:640)&lt;br/&gt;
...&lt;/p&gt;

&lt;p&gt;I have configured the Mongo instance to automatically try to reconnect, but the conversion from &quot;localhost&quot; to &quot;192.168.0.10&quot; only happens once.   The only way to get Mongo to reconnect is to restart the Java instance.&lt;/p&gt;

&lt;p&gt;I assume that there is a reason why the IP is being resolved, but would it be possible to make the driver re-resolve the IP when doing a reconnect?&lt;/p&gt;

&lt;p&gt;Thanks in advance,&lt;br/&gt;
Leif&lt;/p&gt;</description>
                <environment>Mac OS X&lt;br/&gt;
java version &amp;quot;1.6.0_22&amp;quot;&lt;br/&gt;
Java(TM) SE Runtime Environment (build 1.6.0_22-b04-307-9M3263)&lt;br/&gt;
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03-307, mixed mode)&lt;br/&gt;
</environment>
        <key id="15320">JAVA-310</key>
            <summary>Driver reconnect does not detect network IP changes.</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="9">Done</resolution>
                                        <assignee username="jeff.yemin@mongodb.com">Jeffrey Yemin</assignee>
                                    <reporter username="leif">Leif Mortenson</reporter>
                        <labels>
                    </labels>
                <created>Mon, 28 Mar 2011 03:00:52 +0000</created>
                <updated>Wed, 3 Dec 2014 13:10:06 +0000</updated>
                            <resolved>Fri, 12 Jul 2013 00:40:17 +0000</resolved>
                                                    <fixVersion>2.12.0</fixVersion>
                    <fixVersion>3.0.0</fixVersion>
                                    <component>Connection Management</component>
                                        <votes>3</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="506333" author="jeff.yemin" created="Thu, 27 Feb 2014 14:53:13 +0000"  >&lt;p&gt;Hi there,&lt;/p&gt;

&lt;p&gt;If you would like to test the fix for this issue, 2.12.0-rc0 is available either on &lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/releases/tag/r2.12.0-rc0&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;github&lt;/a&gt; or &lt;a href=&quot;http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.12.0-rc0/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Maven Central&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Thanks,&lt;br/&gt;
Jeff&lt;/p&gt;</comment>
                            <comment id="376768" author="auto" created="Tue, 9 Jul 2013 01:57:22 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;jyemin&apos;, u&apos;name&apos;: u&apos;Jeff Yemin&apos;, u&apos;email&apos;: u&apos;jeff.yemin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-310&quot; title=&quot;Driver reconnect does not detect network IP changes.&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-310&quot;&gt;&lt;del&gt;JAVA-310&lt;/del&gt;&lt;/a&gt;: Removed caching of InetSocketAddress in ServerAddress&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/0c0d94a8efd9fad3248316b8dfd03676b7f97174&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/0c0d94a8efd9fad3248316b8dfd03676b7f97174&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="367472" author="jeff.yemin" created="Tue, 25 Jun 2013 17:33:17 +0000"  >&lt;p&gt;Fixed by design in 3.0.x branch.  ServerAddress is immutable and no longer caches InetSocketAddress.  See &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/3.0.x/driver/src/main/org/mongodb/connection/ServerAddress.java#L155&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/blob/3.0.x/driver/src/main/org/mongodb/connection/ServerAddress.java#L155&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="363211" author="hhahn@adobe.com" created="Wed, 19 Jun 2013 09:37:59 +0000"  >&lt;p&gt;This still happens with java mongo driver 2.9.3 on Linux (AWS)&lt;br/&gt;
We are initializing the connection with symbolic names to mongos instances.&lt;br/&gt;
After exchanging / moving a mongos instance to a new EC2 instance (same cname, different internal IP), we get &quot;Server seen down&quot; messages with the correct name, but the old IP in the logs.&lt;/p&gt;

&lt;p&gt;Only way to fix this was to restart the java process.&lt;/p&gt;

&lt;p&gt;Best,&lt;br/&gt;
Heiko&lt;/p&gt;</comment>
                            <comment id="119540" author="jeff.yemin" created="Tue, 15 May 2012 11:23:04 +0000"  >&lt;p&gt;The localhost issue is resolved in &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-249&quot; title=&quot;Java Driver cannot connect to &amp;#39;localhost&amp;#39; when mongod is listening only on 127.0.0.1 (or &amp;quot;localhost&amp;quot;)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-249&quot;&gt;&lt;del&gt;JAVA-249&lt;/del&gt;&lt;/a&gt;.  There is still an issue if the IP address of a non-local server is changed.&lt;/p&gt;</comment>
                            <comment id="27139" author="leif" created="Tue, 29 Mar 2011 18:09:40 +0000"  >&lt;p&gt;Antoine,&lt;br/&gt;
Thank for your attention.  I just posted here because it was unintuitive how it was working.  If you think there is a way to make it work a little better when using &quot;localhost&quot; that would be great.  For me, I am happy with using the localhost IP address directly.  So feel free to close this off.&lt;/p&gt;

&lt;p&gt;Thanks for your help&lt;br/&gt;
Leif&lt;/p&gt;</comment>
                            <comment id="27137" author="antoine" created="Tue, 29 Mar 2011 18:03:21 +0000"  >&lt;p&gt;if you use only 1 server host (either localhost or 127.0.0.1) then the driver will be in mode &quot;direct&quot;, not &quot;replica set&quot;.&lt;br/&gt;
Hence it will only use the local server, instead of detecting and using the master.&lt;br/&gt;
To use replica set you must provide a list of servers (ideally at least 2 servers) and use the hosts as they are defined in the replica set configuration.&lt;br/&gt;
For any further issue on setup or if you just need advice, you should use the google groups.&lt;br/&gt;
As for localhost resolving on mac, we may try to improve it to use 127.&lt;/p&gt;</comment>
                            <comment id="27107" author="leif" created="Tue, 29 Mar 2011 09:16:45 +0000"  >&lt;p&gt;Antoine,&lt;br/&gt;
Understood.  Thank you for looking into it.  I am able to get things working on my machines using the &quot;127.0.0.1&quot; work around.&lt;/p&gt;

&lt;p&gt;I had found that code and did try running InetAddress.getLocalHost().getHostAddress() on my system but that also returns &quot;127.0.01&quot; in the same VM.  So I didn&apos;t think that was what was happening.   I didn&apos;t dig into the code further.&lt;/p&gt;

&lt;p&gt;Unrelated, but is there any particular reason why localhost shouldn&apos;t be used?  We are setting up a clustered application of 3 servers where each server has a mongo instance as well as a Java based web app.  They each point to their localhost mongo and then let the driver and mongo work out which is the master.   We can then do load balancing between the web apps.  This helps keep the system simple and also helps reduce hw costs initially.  Initially there is no sharding, just replication between the 3 mongos for failover and read load balancing of the system.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Leif&lt;/p&gt;</comment>
                            <comment id="26972" author="antoine" created="Mon, 28 Mar 2011 16:19:27 +0000"  >&lt;p&gt;I think the problem is that we added a workaround for resolving localhost on Mac OS, because it could not resolve properly.&lt;br/&gt;
The code to do that is:&lt;/p&gt;

&lt;p&gt;        if ( host.toLowerCase().equals(&quot;localhost&quot;) ){&lt;br/&gt;
            return new InetAddress[] &lt;/p&gt;
{ InetAddress.getLocalHost()}
&lt;p&gt;;&lt;br/&gt;
        }&lt;/p&gt;

&lt;p&gt;The way it works is that it resolves the hostname of the server, not &quot;localhost&quot;, and hence gets the external IP address.&lt;br/&gt;
It is fairly rare that users have the driver on same machine as mongod, besides when doing testing.&lt;br/&gt;
Also, driver is able to update IP address of hosts, but only in replica set mode, and it takes a few minutes to change.&lt;br/&gt;
Agreed it can lead to unexpected behavior but we dont want to do OS detection for Mac.&lt;/p&gt;</comment>
                            <comment id="26954" author="leif" created="Mon, 28 Mar 2011 09:54:09 +0000"  >&lt;p&gt;Scott,&lt;br/&gt;
Thank you for the quick reply.   I am not doing anything intentionally on this machine to map to anything other than 127.0.0.1.&lt;/p&gt;

&lt;p&gt;Just to check:&lt;br/&gt;
1) From the shell:&lt;br/&gt;
&amp;#8212;&lt;br/&gt;
leif$ host localhost&lt;br/&gt;
localhost has address 127.0.0.1&lt;br/&gt;
localhost has IPv6 address ::1&lt;br/&gt;
&amp;#8212;&lt;/p&gt;

&lt;p&gt;2) From within the same JVM, when I run the following code:&lt;br/&gt;
&amp;#8212;&lt;br/&gt;
	InetAddress lh = InetAddress.getByName( &quot;localhost&quot; );&lt;br/&gt;
	System.out.println( &quot;ip: &quot; + lh.getHostAddress() );&lt;br/&gt;
&amp;#8212;&lt;br/&gt;
I get this:&lt;br/&gt;
&amp;#8212;&lt;br/&gt;
ip: 127.0.0.1&lt;br/&gt;
&amp;#8212;&lt;/p&gt;

&lt;p&gt;3) The hosts file has the following:&lt;br/&gt;
&amp;#8212;&lt;br/&gt;
127.0.0.1       localhost&lt;br/&gt;
::1             localhost&lt;br/&gt;
fe80::1%lo0     localhost&lt;br/&gt;
&amp;#8212;&lt;/p&gt;

&lt;p&gt;This all looks correct which is why I was thinking that Mongo is doing something to go out of its way to resolve the IP address.&lt;/p&gt;

&lt;p&gt;If I use the host name &quot;127.0.0.1&quot; rather than &quot;localhost&quot; then everything works as I need.  So this is a workaround for now.  But it is strange that the two would work differently.  &lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Leif&lt;/p&gt;</comment>
                            <comment id="26953" author="scotthernandez" created="Mon, 28 Mar 2011 06:01:40 +0000"  >&lt;p&gt;Why is your machine setup to resolve localhost to something other than 127.0.0.1? Why not just use 127.0.0.1 as the address you connect to?&lt;/p&gt;

&lt;p&gt;There are performance reasons why it is best not to resolve the address on every use; also with a connection pool it can be complicated but it would make sense to call ServerAddress.updateInetAddr() (which reresolves the name) if there are no sockets in the pool.&lt;/p&gt;
</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="58168">JAVA-707</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="172361">JAVA-1582</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="101332">CSHARP-869</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="14161">JAVA-249</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="172361">JAVA-1582</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <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|hrhcc7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14799</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>