RUBY-3743 Correctly implement srv_max_hosts option#2973
RUBY-3743 Correctly implement srv_max_hosts option#2973kyleburgess2025 merged 5 commits intomongodb:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements spec changes from DRIVERS-1519 for SRV monitoring with srvMaxHosts support. The changes ensure that the srv_max_hosts parameter is properly passed through the monitoring system and that SRV resolution failures are handled according to specification requirements.
Key Changes:
- Modified SRV resolver to not raise errors on invalid domain verification per spec
- Updated SRV monitor and URI parser to pass through
srv_max_hostsandsrv_service_nameoptions from both URI and client options - Added comprehensive test coverage for
srv_max_hostsfunctionality in the SRV monitor
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| spec/mongo/srv/monitor_spec.rb | Adds test cases verifying that srv_max_hosts limits cluster hosts and is correctly passed to the resolver |
| lib/mongo/uri/srv_protocol.rb | Changes resolver to use raise_on_invalid: false and adds fallback logic for srv_service_name and srv_max_hosts options |
| lib/mongo/srv/monitor.rb | Updates scan! method to pass srv_service_name and srv_max_hosts options to resolver |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/mongo/uri/srv_protocol.rb
Outdated
| hostname, | ||
| uri_options[:srv_service_name] || options[:srv_service_name], |
There was a problem hiding this comment.
Removed trailing whitespace from lines 155 and 156.
| hostname, | |
| uri_options[:srv_service_name] || options[:srv_service_name], | |
| hostname, | |
| uri_options[:srv_service_name] || options[:srv_service_name], |
jamis
left a comment
There was a problem hiding this comment.
Looks great! Optionally: cleaning up that line I mentioned in srv/resolver.rb, but that is clearly outside the scope of this ticket, so I'll leave that up to you.
|
Locally tested these changes using the following script: require 'logger'
require 'debug'
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
# gem 'mongoid', '~> 7.5.4'
gem 'mongo', path: __dir__
end
Mongo::Logger.logger = Logger.new($stdout)
Mongo::Logger.logger.level = Logger::INFO
URL = 'mongodb+srv://test1.test.build.10gen.cc/?tls=false'
client = Mongo::Client.new(URL, connect_timeout: 5, server_selection_timeout: 10, socket_timeout: 5, srv_max_hosts: 1)
puts "==== size: #{client.cluster.addresses.size}"
sleep(5)
puts "==== size: #{client.cluster.addresses.size}"
URL_WITH_MAX_HOSTS = 'mongodb+srv://test1.test.build.10gen.cc/?tls=false&srvMaxHosts=1'
client2 = Mongo::Client.new(URL_WITH_MAX_HOSTS, connect_timeout: 5, server_selection_timeout: 10, socket_timeout: 5)
puts "==== size: #{client2.cluster.addresses.size}"
sleep(5)
puts "==== size: #{client2.cluster.addresses.size}"Output: |
This finishes the implementation of the spec changes for DRIVERS-1519:
srv_max_hostsoptionsrv_max_hostsoption in the Mongo client builder from being usedraise_on_invalidin the SRV resolver to false to adhere to spec requirements