-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: Connection Management
-
Fully Compatible
-
Java Drivers
-
Needed
-
Summary
Affects any MongoDB driver version from 4.11.x onwards (when SOCKS proxy support was introduced).
Unable to connect: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=REPLICA_SET, servers=[{address=ip-10-10-10-10.ec2.internal:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketException: ip-10-10-10-10.ec2.internal is not an IP string literal}}
On connect, the Socks Socket determines if the remote address is either a domain name or IPvN address but fails with the above exception when dealing with names such as EC2 guest OS hostnames explained here
The problem seems to be the regex used for validating if the address is domain name is too restrictive.
A more inclusive pattern could be:
^(?!:\/\/)(?=[a-zA-Z0-9\-\.]{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9\-]+\.?|localhost)$