[JAVA-2593] ServerAddress#sameHost method fails to handle IPV6 addresses correctly Created: 04/Sep/17  Updated: 29/Oct/23  Resolved: 08/Sep/17

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

Type: Bug Priority: Major - P3
Reporter: Sewon Kim [X] Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

ServerAddress#sameHost does not handle IPV6 addresses correctly.

Was:

IPV6 hosts problems in Replica set configurations.

I use 3.4.3 driver for mongo.
and I set replica 3 servers for mongodb with ipv6 configuration.

1. three mongo servers with IPV4(the replica configurations), it works fine.
2. on the single machine with IPV6 with mongo, it works fine.

but three mongo servers with IPV6(the replica configurations)
and the clients and rs.status() it is normal.

I add the replica configurations with java driver.
this is my Constructor. and I use "[" ,"]" for ipv6.

  • MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList, MongoClientOptions options)

but below logs continue and it didn't work.
and I looked the code.

I guess why MultiServerCluster.java calls "sameHost" method. but gives without "[","]" host.

if I have faults to set, can you tell me the correct way?

 
 WARN <2017-09-04 11:48:41>[o.m.d.c.event:91] Exception thrown raising server description changed event to listener com.mongodb.connection.MultiServerCluster$DefaultServerStateListener@699320af
java.lang.NumberFormatException: For input string: "da12:465:7e00:12a7:1e2e:4f8b:b73a]:27017"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_92]
	at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_92]
	at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_92]
	at com.mongodb.ServerAddress.sameHost(ServerAddress.java:226) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster.handleReplicaSetMemberChanged(MultiServerCluster.java:218) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster.onChange(MultiServerCluster.java:165) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster.access$100(MultiServerCluster.java:46) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster$DefaultServerStateListener.serverDescriptionChanged(MultiServerCluster.java:126) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.event.ServerEventMulticaster.serverDescriptionChanged(ServerEventMulticaster.java:92) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.DefaultServer$DefaultServerStateListener.stateChanged(DefaultServer.java:196) [mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:148) [mongodb-driver-core-3.4.2.jar:na]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_92]
 WARN <2017-09-04 11:48:41>[o.m.d.c.event:91] Exception thrown raising server description changed event to listener com.mongodb.connection.MultiServerCluster$DefaultServerStateListener@41418a91
java.lang.NumberFormatException: For input string: "da12:465:7e00:92b4:796c:d92c:5b84]:27017"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_92]
	at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_92]
	at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_92]
	at com.mongodb.ServerAddress.sameHost(ServerAddress.java:226) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster.handleReplicaSetMemberChanged(MultiServerCluster.java:218) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster.onChange(MultiServerCluster.java:165) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster.access$100(MultiServerCluster.java:46) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster$DefaultServerStateListener.serverDescriptionChanged(MultiServerCluster.java:126) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.event.ServerEventMulticaster.serverDescriptionChanged(ServerEventMulticaster.java:92) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.DefaultServer$DefaultServerStateListener.stateChanged(DefaultServer.java:196) [mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:148) [mongodb-driver-core-3.4.2.jar:na]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_92]
 WARN <2017-09-04 11:48:41>[o.m.d.c.event:91] Exception thrown raising server description changed event to listener com.mongodb.connection.MultiServerCluster$DefaultServerStateListener@25fede36
java.lang.NumberFormatException: For input string: "da12:465:7e00:8fd1:1567:4cd7:9fb2]:27017"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_92]
	at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_92]
	at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_92]
	at com.mongodb.ServerAddress.sameHost(ServerAddress.java:226) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster.handleReplicaSetMemberChanged(MultiServerCluster.java:218) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster.onChange(MultiServerCluster.java:165) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster.access$100(MultiServerCluster.java:46) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.MultiServerCluster$DefaultServerStateListener.serverDescriptionChanged(MultiServerCluster.java:126) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.event.ServerEventMulticaster.serverDescriptionChanged(ServerEventMulticaster.java:92) ~[mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.DefaultServer$DefaultServerStateListener.stateChanged(DefaultServer.java:196) [mongodb-driver-core-3.4.2.jar:na]
	at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:148) [mongodb-driver-core-3.4.2.jar:na]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_92]



 Comments   
Comment by Sewon Kim [X] [ 06/Sep/17 ]

Thank you for all.

Comment by Ross Lawley [ 06/Sep/17 ]

Scheduled to be backported to 3.5.1

Comment by Ross Lawley [ 06/Sep/17 ]

Thanks Sewon Kim,

I found the cause and a fix will be released in the 3.6.0 release.

All the best,

Ross

Comment by Githook User [ 05/Sep/17 ]

Author:

{'username': 'rozza', 'name': 'Ross Lawley', 'email': 'ross.lawley@gmail.com'}

Message: Ensure ServerAddress#sameHost parses IPV6 addresses correctly

JAVA-2593
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/bd2d280d1de0d55f5fde051e8b5ccdea02084c39

Comment by Sewon Kim [X] [ 05/Sep/17 ]

@Ross Lawley Thanks for your replies. Do I need to explain more?

Comment by Ross Lawley [ 04/Sep/17 ]

Hi Sewon Kim,

I have found the issue and a fix will be released in the next version of the driver.

Ross

Comment by Ross Lawley [ 04/Sep/17 ]

Hi Sewon Kim,

Can you provide me an example of how you creating the ServerAddress?
Also can you confirm the version of the Java driver you are using?

Ross

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