[JAVA-310] Driver reconnect does not detect network IP changes. Created: 28/Mar/11 Updated: 03/Dec/14 Resolved: 12/Jul/13 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Connection Management |
| Affects Version/s: | None |
| Fix Version/s: | 2.12.0, 3.0.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Leif Mortenson | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 3 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Mac OS X |
||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
Our application runs on machines that are sometimes moved between networks or has its IP address changed. When we create the Mongo instance it is done using the "localhost" host for the Mongo server. The Mongo driver appears to always resolve to an IP on the local subnet. "192.168.0.10" for example. When the network chances however, our applications starts failing with errors like the following because it can no longer connect: jvm 1 | java.io.IOException: couldn't connect to [io/192.168.0.10:27017] bc:java.net.ConnectException: Operation timed out I have configured the Mongo instance to automatically try to reconnect, but the conversion from "localhost" to "192.168.0.10" only happens once. The only way to get Mongo to reconnect is to restart the Java instance. 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? Thanks in advance, |
| Comments |
| Comment by Jeffrey Yemin [ 27/Feb/14 ] |
|
Hi there, If you would like to test the fix for this issue, 2.12.0-rc0 is available either on github or Maven Central. Thanks, |
| Comment by auto [ 09/Jul/13 ] |
|
Author: {u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}Message: |
| Comment by Jeffrey Yemin [ 25/Jun/13 ] |
|
Fixed by design in 3.0.x branch. ServerAddress is immutable and no longer caches InetSocketAddress. See |
| Comment by Heiko Hahn [ 19/Jun/13 ] |
|
This still happens with java mongo driver 2.9.3 on Linux (AWS) Only way to fix this was to restart the java process. Best, |
| Comment by Jeffrey Yemin [ 15/May/12 ] |
|
The localhost issue is resolved in |
| Comment by Leif Mortenson [ 29/Mar/11 ] |
|
Antoine, Thanks for your help |
| Comment by Antoine Girbal [ 29/Mar/11 ] |
|
if you use only 1 server host (either localhost or 127.0.0.1) then the driver will be in mode "direct", not "replica set". |
| Comment by Leif Mortenson [ 29/Mar/11 ] |
|
Antoine, I had found that code and did try running InetAddress.getLocalHost().getHostAddress() on my system but that also returns "127.0.01" in the same VM. So I didn't think that was what was happening. I didn't dig into the code further. Unrelated, but is there any particular reason why localhost shouldn'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. Thanks, |
| Comment by Antoine Girbal [ 28/Mar/11 ] |
|
I think the problem is that we added a workaround for resolving localhost on Mac OS, because it could not resolve properly. if ( host.toLowerCase().equals("localhost") ){ ; The way it works is that it resolves the hostname of the server, not "localhost", and hence gets the external IP address. |
| Comment by Leif Mortenson [ 28/Mar/11 ] |
|
Scott, Just to check: 2) From within the same JVM, when I run the following code: 3) The hosts file has the following: 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. If I use the host name "127.0.0.1" rather than "localhost" then everything works as I need. So this is a workaround for now. But it is strange that the two would work differently. Thanks, |
| Comment by Scott Hernandez (Inactive) [ 28/Mar/11 ] |
|
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? 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. |