[JAVA-430] Connection to mongodb://localhost:27017 gets UnknownHostException if machine's hostname doesn't resolve Created: 07/Sep/11  Updated: 19/Oct/16  Resolved: 15/May/12

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: John Feibusch Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.0 (Santiago)
$ java -version
java version "1.6.0_17"
OpenJDK Runtime Environment (IcedTea6 1.7.4) (rhel-1.21.b17.el6-x86_64)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)


Issue Links:
Duplicate
duplicates JAVA-249 Java Driver cannot connect to 'localh... Closed

 Description   

If the machine's hostname does not resolve, then the following line will cause an UnknownHostException:
ServerAddress sa=new ServerAddress("mongodb://localhost:27017");

That's because the constructor for ServerAddress recognises the string "localhost" and calls InetAddress.getLocalHost(). This issue does not occur if you use "127.0.0.1" instead of "localhost".

If you feel this is intended behavior, would you consider noting it in the documentation.



 Comments   
Comment by Jeffrey Yemin [ 15/May/12 ]

Not intended, and it's fixed in JAVA-249

Generated at Thu Feb 08 08:52:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.