[JAVA-3660] Mongo Driver Socket Connect Exception Created: 12/Mar/20  Updated: 27/Oct/23  Resolved: 12/Mar/20

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

Type: Bug Priority: Major - P3
Reporter: Vijay Babu Batta Assignee: Ross Lawley
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux, Mongo Driver version 3.6.2.


Attachments: Java Source File MongoPlayer.java    

 Description   

Hello,

When we are creating a MongoClient using the uir, even if the connection is unsuccessful, system is not throwing out the error, however in the log file, it will show the error message as below. I am attaching the file that I have tested with.

 

Mar 12, 2020 1:24:12 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[localhost1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Mar 12, 2020 1:24:12 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Exception in monitor thread while connecting to server localhost1:27017
com.mongodb.MongoSocketException: localhost1: No address associated with hostname
at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:188)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:59)
at com.mongodb.connection.SocketStream.open(SocketStream.java:57)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.UnknownHostException: localhost1: No address associated with hostname
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
at java.net.InetAddress.getAllByName0(InetAddress.java:1277)
at java.net.InetAddress.getAllByName(InetAddress.java:1193)
at java.net.InetAddress.getAllByName(InetAddress.java:1127)
at java.net.InetAddress.getByName(InetAddress.java:1077)
at com.mongodb.ServerAddress.getSocketAddress(ServerAddress.java:186)
... 5 more

 

 

 

 



 Comments   
Comment by Vijay Babu Batta [ 12/Mar/20 ]

Hi Ross,

Thank you very much for clarifying. We will see if we can trigger some dummy command and test then.

Appreciate your help.

 

Comment by Ross Lawley [ 12/Mar/20 ]

Hi vijaybabu.batta@sirmaindia.com,

That's also to be expected as the driver uses a connection pool in the background and its the monitor thread that is throwing an exception. You would only see an error in your application when calling a command.

All the best,

Ross

Comment by Vijay Babu Batta [ 12/Mar/20 ]

Hi Ross,

Thank you for your quick response.

My query is related to the issue only. Apologies for not elaborating clearly.

I have given localhost1 intentionally so that connection fails. However, in my code, is continues without going into the exception block. After a bit of study, what i have found was that, inside mongo driver code, it is logging the error to the console which is what i have pasted above, but it will not return the error outside.

Here, my motive behind this is, If connection is not established to the server, I should know immediately in the code which is not happening.

Looking forward for your help.

PS: Thank you on pointing me to the community.

 

 

 

Comment by Ross Lawley [ 12/Mar/20 ]

Hi vijaybabu.batta@sirmaindia.com,

Please check the cause of the exception: Caused by: java.net.UnknownHostException: localhost1: No address associated with hostname. The error indicates that there is no IP address associated with the host localhost1. I imagine its a typo and the host should be localhost.

Just to let you know for future reference, this project is for Java driver bugs or feature requests. The best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb community forum as you will reach a broader audience there. If your business requires an answer from MongoDB within a time frame then we do offer production support.

All the best,

Ross

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