[CDRIVER-2044] Max URI set to only 64 chars Created: 10/Feb/17  Updated: 07/Jun/17  Resolved: 07/Apr/17

Status: Closed
Project: C Driver
Component/s: uri
Affects Version/s: None
Fix Version/s: 1.7.0

Type: Improvement Priority: Major - P3
Reporter: Hannes Magnusson Assignee: Hannes Magnusson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-1129 Silent failure parsing hostnames long... Closed

 Description   

When attempting to connect to a dns name longer then 64 chars, mongoc will erroneously fail preemptively because the hostname is longer then HOST_NAME_MAX.

./mongoc-ping "mongodb://abcdefghijklmnopqrstuvwxyz.1234567890.ABCDEFGHIJKLMNOPQRSTUVWXYZ.vcap.me"
2017/02/10 10:03:35.0051: [ 8490]:    ERROR:       mongoc: Hostname provided in URI is too long, max is 64 chars
Invalid hostname or port: mongodb://abcdefghijklmnopqrstuvwxyz.1234567890.ABCDEFGHIJKLMNOPQRSTUVWXYZ.vcap.me

The hostname works just fine, as dns names can be up to 255 chars.
So removing this limitation, and it works fine:

git diff
diff --git a/src/mongoc/mongoc-host-list.h b/src/mongoc/mongoc-host-list.h
index de1689d..6e1397e 100644
--- a/src/mongoc/mongoc-host-list.h
+++ b/src/mongoc/mongoc-host-list.h
@@ -34,7 +34,7 @@ BSON_BEGIN_DECLS
 #define BSON_HOST_NAME_MAX 255
 #endif
 #else
-#define BSON_HOST_NAME_MAX HOST_NAME_MAX
+#define BSON_HOST_NAME_MAX 255
 #endif
 
 
 bjori@TaylorSwift  ~/Sources/mongoc   master ●  ./mongoc-ping "mongodb://abcdefghijklmnopqrstuvwxyz.1234567890.ABCDEFGHIJKLMNOPQRSTUVWXYZ.vcap.me"
{ "ok" : 1.0 }



 Comments   
Comment by Githook User [ 07/Apr/17 ]

Author:

{u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}

Message: CDRIVER-2044 Max URI set to only 64 chars

HOST_NAME_MAX determines the maximum length gethostname() returns,
not the maximum dns name we can resolve or connect to.
As each label cannot be longer then 64, which is why HOST_NAME_MAX is
limited to 64, and should in turn not be used to limit dns names.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/ed0f73a7a68d49f39e104009e8597c22ac73ef05

Comment by Hannes Magnusson [ 10/Feb/17 ]

MongoDB, on that same host, has no qualms connecting to replicaset members using hostnames all the way up 255 chars:

{ "ok" : 1 }
> rs.status()
{
	"set" : "foobar",
	"date" : ISODate("2017-02-10T18:20:46.486Z"),
	"myState" : 1,
	"term" : NumberLong(1),
	"heartbeatIntervalMillis" : NumberLong(2000),
	"optimes" : {
		"lastCommittedOpTime" : {
			"ts" : Timestamp(1486750835, 1),
			"t" : NumberLong(1)
		},
		"appliedOpTime" : {
			"ts" : Timestamp(1486750845, 1),
			"t" : NumberLong(1)
		},
		"durableOpTime" : {
			"ts" : Timestamp(1486750845, 1),
			"t" : NumberLong(1)
		}
	},
	"members" : [
		{
			"_id" : 1,
			"name" : "abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.vcap.me:27017",
			"health" : 1,
			"state" : 1,
			"stateStr" : "PRIMARY",
			"uptime" : 492,
			"optime" : {
				"ts" : Timestamp(1486750845, 1),
				"t" : NumberLong(1)
			},
			"optimeDate" : ISODate("2017-02-10T18:20:45Z"),
			"electionTime" : Timestamp(1486750649, 1),
			"electionDate" : ISODate("2017-02-10T18:17:29Z"),
			"configVersion" : 5,
			"self" : true
		},
		{
			"_id" : 2,
			"name" : "abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.vcap.me:27019",
			"health" : 1,
			"state" : 2,
			"stateStr" : "SECONDARY",
			"uptime" : 207,
			"optime" : {
				"ts" : Timestamp(1486750835, 1),
				"t" : NumberLong(1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(1486750835, 1),
				"t" : NumberLong(1)
			},
			"optimeDate" : ISODate("2017-02-10T18:20:35Z"),
			"optimeDurableDate" : ISODate("2017-02-10T18:20:35Z"),
			"lastHeartbeat" : ISODate("2017-02-10T18:20:45.021Z"),
			"lastHeartbeatRecv" : ISODate("2017-02-10T18:20:45.277Z"),
			"pingMs" : NumberLong(0),
			"configVersion" : 4
		},
		{
			"_id" : 3,
			"name" : "abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.vcap.me:27018",
			"health" : 1,
			"state" : 2,
			"stateStr" : "SECONDARY",
			"uptime" : 133,
			"optime" : {
				"ts" : Timestamp(1486750835, 1),
				"t" : NumberLong(1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(1486750835, 1),
				"t" : NumberLong(1)
			},
			"optimeDate" : ISODate("2017-02-10T18:20:35Z"),
			"optimeDurableDate" : ISODate("2017-02-10T18:20:35Z"),
			"lastHeartbeat" : ISODate("2017-02-10T18:20:45.021Z"),
			"lastHeartbeatRecv" : ISODate("2017-02-10T18:20:45.277Z"),
			"pingMs" : NumberLong(0),
			"configVersion" : 4
		},
		{
			"_id" : 4,
			"name" : "abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghi.vcap.me:27020",
			"health" : 0,
			"state" : 8,
			"stateStr" : "(not reachable/healthy)",
			"uptime" : 0,
			"optime" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
			"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
			"lastHeartbeat" : ISODate("2017-02-10T18:20:45.028Z"),
			"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
			"pingMs" : NumberLong(0),
			"lastHeartbeatMessage" : "HostUnreachable",
			"configVersion" : -1
		},
		{
			"_id" : 5,
			"name" : "abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefg.vcap.me:27020",
			"health" : 0,
			"state" : 8,
			"stateStr" : "(not reachable/healthy)",
			"uptime" : 0,
			"optime" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
			"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
			"lastHeartbeat" : ISODate("2017-02-10T18:20:45.028Z"),
			"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
			"pingMs" : NumberLong(0),
			"lastHeartbeatMessage" : "HostUnreachable",
			"configVersion" : -1
		},
		{
			"_id" : 6,
			"name" : "abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghijklmnopqrstuvwxyz.a0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.abcde.vcap.me:27020",
			"health" : 1,
			"state" : 0,
			"stateStr" : "STARTUP",
			"uptime" : 1,
			"optime" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(0, 0),
				"t" : NumberLong(-1)
			},
			"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
			"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
			"lastHeartbeat" : ISODate("2017-02-10T18:20:45.021Z"),
			"lastHeartbeatRecv" : ISODate("2017-02-10T18:20:45.440Z"),
			"pingMs" : NumberLong(0),
			"configVersion" : -2
		}
	],
	"ok" : 1
}

Generated at Wed Feb 07 21:13:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.