The documentation and original spec imply to me that the result of the SRV lookup ends up being equivalent having the member hosts supplied up front.
For example, if you specify connection string mongo+srv://mongo.foo.cluster.local
, and the result from an SRV lookup against _mongodb._tcp.mongo.foo.cluster.local
:
mongo-0.mongo.foo.cluster.local
mongo-1.mongo.foo.cluster.local
mongo-2.mongo.foo.cluster.local
… then client libraries would end up treating this equivalent to if you had originally supplied mongodb://mongo-0.mongo.foo.cluster.local,mongo-1.mongo.foo.cluster.local,mongo-2.mongo.foo.cluster.local
when establishing the initial connection.
However, I’ve noticed that client libraries also poll SRV lookups, and the consequences of this are somewhat unclear to me. When querying SRV records in a kubernetes cluster, you’re likely to find that absent pods are no longer returned… so for example, if you were to rollout restart a statefulset, you’ll find the returned record changes in relatively rapid succession.
My concern is, I don’t understand the implications of this polling behaviour and the way in which the record will change over the space of a minute or two. If client libraries see members absent from an SRV lookup, do they then treat them as if they’ve been removed from the replica set, and drop any connections they have to them?
My main worry is circumstances like:
- mongo-2 is terminating
- client shuts down any connections to mongo-2
- DNS polling in client performs a DNS lookup, sees mongo-2 is absent, removes any notion of them
- DNS polling sleeps for 60 seconds
- mongo-2 comes back up
- mongo-1 is terminating
- client shuts down any connections to mongo-1
… is the client now in a state where it only has a connection to mongo-0? Or will it have re-established a connection via other channels once mongo-2 has come back up?
I think the part that is particularly confusing me is, on the notion that the result from an SRV lookup acts as an initial seed list, I don’t really understand why this subsequent polling occurs.