[GODRIVER-777] Does the Go Driver cache DNS and if so how long? Created: 21/Jan/19  Updated: 11/Sep/19  Resolved: 01/Mar/19

Status: Closed
Project: Go Driver
Component/s: Options & Configuration
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Wesley Porter Assignee: David Golden
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates DRIVERS-521 Allow custom service names with srvSe... Implementing

 Description   

I am using Consul for service discovery with a MongoDB replica set. In Consul, I have an address for a primary node (e.g. mongo-primary.service.consul). To connect, I use the following connection string:

 

mongodb://<user>:<password>@mongo-primary.service.consul:27017/feed?replicaSet=rs&connect=direct

 

1.) Is this a safe way to connect to my replica set? Does the Go driver cache DNS connections? Is there a way for me to configure the cache TTL?

2.) Is there a way for me to connect this way without the option connect=direct? Is that expected when connecting directly to the primary?



 Comments   
Comment by David Golden [ 01/Mar/19 ]

To clarify my comment: Consul follows the technical details of RFC-2782, but expands the definition of service and protocol. In RFC-2782, a "service" is described as a singular "well-known" name, such as "ldap" or "imap" from /etc/services and a "protocol" is a symbolic IP protocol name. However, Consul allows (mandates?) the use of custom service names ("my-mongo" in your case) and allows tags in place of protocols. The current design of the mongodb+srv scheme conforms narrowly to the definitions of RFC-2782, with a "well-known" service name of "mongodb" and the TCP protocol.

I'll close this as a duplicate.

Comment by Wesley Porter [ 01/Mar/19 ]

Hi David,

 

Thank you for the reply! Consul's way of doing things does follow RFC 2782. https://www.consul.io/docs/agent/dns.html#rfc-2782-lookup

 

It looks like this ticket is a duplicate then of DRIVERS-521.

Comment by David Golden [ 01/Mar/19 ]

Hi. This issue has come up before in DRIVERS-521. Our current design is strict against the RFC and doesn't currently allow custom service names. Please consider following that ticket for any updates.

In the mean time, our recommendation is to use different domain names for different MongoDB clusters rather than different service names.

Comment by PJ Tatlow [ 19/Feb/19 ]

Hi Jeff, we're trying to use the "mongodb+srv" syntax, but we're running into a problem. Consul does support DNS SRV records, but it looks like the driver is trying to a "RFC 2782 Lookup" which isn't working. For example, I can do

dig my-mongo.service.consul SRV

and it finds all of the nodes with the correct port. But when I try connecting to mongo with

mongodb+srv://<user>:<password>@xm-feed-mongo.service.consul/?replicaSet=rs&ssl=false

it fails because it can't find "_mongodb._tcp.my-mongo.service.consul". It looks like consul DOES support these type of lookups but it needs the address to be something like "_my-mongo._tcp.service.consul". Is there a way to either stop the driver from adding the "_mongodb._tcp" prefix to the address? If not, is there a way to customize the service name in the prefix?

Comment by Jeffrey Yemin [ 29/Jan/19 ]

Hi wesp,

Generally the correct way to connect to a replica set is to use specify a connection string that:

  1. Includes more than one member. That way if one of the members is down for maintenance, the driver can still connect to one of the others
  2. Specifies the replica set name. You did this already. It's not required, but it's a good sanity check
  3. Does not include connect=direct. That option should only be used in special circumstances, usually when you want to perform some administrative operation on a specific server. Given the way replica sets work, it's better to let the driver discover which server is the primary rather than making an assumption about which member is primary.

I'm not too familiar with Consul, so that may place additional constraints on what you're trying to accomplish. If Consul allows you to maintain DNS SRV records, you can use the driver's support for the mongodb+srv connection string protocol. Seethis blog post for a description.

Hope this helps.

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