Skip to content

Conversation

@kyleburgess2025
Copy link
Contributor

@kyleburgess2025 kyleburgess2025 commented Jan 5, 2026

  • Changes SRV monitoring to correctly use the srv_max_hosts option
  • Fixes the bug that prevented the srv_max_hosts option in the Mongo client builder from being used
  • Changes the default for raise_on_invalid in the SRV resolver to false to adhere to spec requirements

@kyleburgess2025 kyleburgess2025 marked this pull request as ready for review January 5, 2026 21:35
@kyleburgess2025 kyleburgess2025 requested a review from a team as a code owner January 5, 2026 21:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_hosts and srv_service_name options from both URI and client options
  • Added comprehensive test coverage for srv_max_hosts functionality 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.

Comment on lines 155 to 156
hostname,
uri_options[:srv_service_name] || options[:srv_service_name],
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed trailing whitespace from lines 155 and 156.

Suggested change
hostname,
uri_options[:srv_service_name] || options[:srv_service_name],
hostname,
uri_options[:srv_service_name] || options[:srv_service_name],

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@jamis jamis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kyleburgess2025 kyleburgess2025 merged commit 10bfb18 into mongodb:master Jan 6, 2026
167 checks passed
@kyleburgess2025
Copy link
Contributor Author

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:

W, [2026-01-05T10:44:44.023231 #72997]  WARN -- : MONGODB | Error checking localhost.test.build.10gen.cc:27017: Mongo::Error::SocketError: Errno::ECONNREFUSED: Connection refused - connect(2) for 127.0.0.1:27017 (for 127.0.0.1:27017 (no TLS)) (on localhost.test.build.10gen.cc:27017)
==== size: 1
==== size: 1
W, [2026-01-05T10:44:49.469193 #72997]  WARN -- : MONGODB | Error checking localhost.test.build.10gen.cc:27017: Mongo::Error::SocketError: Errno::ECONNREFUSED: Connection refused - connect(2) for 127.0.0.1:27017 (for 127.0.0.1:27017 (no TLS)) (on localhost.test.build.10gen.cc:27017)
==== size: 1
W, [2026-01-05T10:44:54.028700 #72997]  WARN -- : MONGODB | Error checking localhost.test.build.10gen.cc:27017: Mongo::Error::SocketError: Errno::ECONNREFUSED: Connection refused - connect(2) for 127.0.0.1:27017 (for 127.0.0.1:27017 (no TLS)) (on localhost.test.build.10gen.cc:27017)
==== size: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants