[JAVA-1582] MongoClient constructor throws exception if one of the seed endpoints in MongoURI is not resolved by DNS Created: 02/Dec/14  Updated: 03/Dec/14  Resolved: 03/Dec/14

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

Type: Bug Priority: Major - P3
Reporter: Yuri Finkelstein Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongo-java-driver: 2.11.3


Issue Links:
Duplicate
duplicates JAVA-310 Driver reconnect does not detect netw... Closed
Related
related to JAVA-310 Driver reconnect does not detect netw... Closed

 Description   

If one of the seed endpoints in mongo URI is not DNS resolvable MongoClient throws exception, even though there are other valid endpoints in the URI (the client is trying to connect to a replica set).

I believe it's a bug and the exception should not be thrown in this case.

 -- -- -- --caused by: phx7b01c-14c5-8.stratus.phx.ebay.com
  -- -- -- -- -- java.net.InetAddress.getAllByName0(InetAddress.java:1250)
  -- -- -- -- -- java.net.InetAddress.getAllByName(InetAddress.java:1162)
  -- -- -- -- -- java.net.InetAddress.getAllByName(InetAddress.java:1098)
  -- -- -- -- -- java.net.InetAddress.getByName(InetAddress.java:1048)
  -- -- -- -- -- com.mongodb.ServerAddress.updateInetAddress(ServerAddress.java:204)
  -- -- -- -- -- com.mongodb.ServerAddress.<init>(ServerAddress.java:73)
  -- -- -- -- -- com.mongodb.ServerAddress.<init>(ServerAddress.java:46)
  -- -- -- -- -- com.mongodb.Mongo.getMongoAuthorityFromURI(Mongo.java:628)
  -- -- -- -- -- com.mongodb.Mongo.<init>(Mongo.java:318)
  -- -- -- -- -- com.mongodb.MongoClient.<init>(MongoClient.java:269)



 Comments   
Comment by Yuri Finkelstein [ 03/Dec/14 ]

Thanks, makes sense.
This ticket can be closed.
Yuri

Comment by Jeffrey Yemin [ 02/Dec/14 ]

Since UnknownHostException is a checked exception, I considered it too invasive in a minor release to remove it from the method declarations, as anyone who recompiled would get a compilation error.

Comment by Yuri Finkelstein [ 02/Dec/14 ]

Thanks for the info. Why declare the exception then?

Comment by Jeffrey Yemin [ 02/Dec/14 ]

JAVA-310, fixed in 2.12.0, resolves this issue as well. Although ServerAddress constructor is still declared to throw UnknownHostException in 2.12.0, it no longer actually throws it, as DNS resolution is now delayed until the driver calls ServerAddress#getSocketAddress, which does not happen within the MongoClient constructor.

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