Skip to content

Commit 10bfb18

Browse files
RUBY-3743 Finish implementing spec changes from DRIVERS-1519 (#2973)
* Adding needed changes to adhere to spec + fixing srv_max_hosts bug * removing unneeded changes * Adding tests for srv_max_hosts * Adding tests to ensure srv_max_hosts is set if set in client * Whitespace + adding comment about priority of srv_max_hosts
1 parent 5e64c1d commit 10bfb18

File tree

4 files changed

+229
-138
lines changed

4 files changed

+229
-138
lines changed

lib/mongo/client.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ def hash
357357
# that the driver will communicate with for sharded topologies. If this
358358
# option is 0, then there will be no maximum number of mongoses. If the
359359
# given URI resolves to more hosts than ``:srv_max_hosts``, the client
360-
# will ramdomly choose an ``:srv_max_hosts`` sized subset of hosts.
360+
# will randomly choose an ``:srv_max_hosts`` sized subset of hosts. If
361+
# srvMaxHosts is provided in the URI options, it takes precedence over this
362+
# option.
361363
# @option options [ String ] :srv_service_name The service name to use in
362364
# the SRV DNS query.
363365
# @option options [ true, false ] :ssl Whether to use TLS.

lib/mongo/srv/monitor.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ def do_work
7272
def scan!
7373
begin
7474
last_result = Timeout.timeout(timeout) do
75-
@resolver.get_records(@srv_uri.query_hostname)
75+
@resolver.get_records(
76+
@srv_uri.query_hostname,
77+
@srv_uri.uri_options[:srv_service_name] || options[:srv_service_name],
78+
@srv_uri.uri_options[:srv_max_hosts] || @options[:srv_max_hosts]
79+
)
7680
end
7781
rescue Resolv::ResolvTimeout => e
7882
log_warn("SRV monitor: timed out trying to resolve hostname #{@srv_uri.query_hostname}: #{e.class}: #{e}")

lib/mongo/uri/srv_protocol.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ def raise_invalid_error!(details)
122122
end
123123

124124
# Gets the SRV resolver.
125+
# If domain verification fails or no SRV records are found,
126+
# an error must not be raised per the spec; instead, a warning is logged.
125127
#
126128
# @return [ Mongo::Srv::Resolver ]
127129
def resolver
128130
@resolver ||= Srv::Resolver.new(
129-
raise_on_invalid: true,
131+
raise_on_invalid: false,
130132
resolv_options: options[:resolv_options],
131133
timeout: options[:connect_timeout],
132134
)
@@ -149,7 +151,11 @@ def parse!(remaining)
149151

150152
log_debug "attempting to resolve #{hostname}"
151153

152-
@srv_result = resolver.get_records(hostname, uri_options[:srv_service_name], uri_options[:srv_max_hosts])
154+
@srv_result = resolver.get_records(
155+
hostname,
156+
uri_options[:srv_service_name] || options[:srv_service_name],
157+
uri_options[:srv_max_hosts] || options[:srv_max_hosts]
158+
)
153159
if srv_result.empty?
154160
raise Error::NoSRVRecords.new(NO_SRV_RECORDS % hostname)
155161
end

0 commit comments

Comments
 (0)