Skip to content

RUBY-3699 Fix ArgumentError when a server is marked unknown #2949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/mongo/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,9 @@ def unknown!(options = {})
return
end

if options[:generation] && options[:generation] < pool&.generation
# NOTE: You cannot use safe navigation here because if pool is nil you end
# up trying to evaluate Integer < nil which is invalid.
if options[:generation] && pool && options[:generation] < pool.generation
return
end

Expand Down
13 changes: 13 additions & 0 deletions spec/mongo/server/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ class ConnectionSpecTestException < Exception; end
it_behaves_like 'marks server unknown'
it_behaves_like 'logs a warning'
it_behaves_like 'adds server diagnostics'

context 'when the error includes a generation' do
let(:exception) do
Mongo::Error::SocketError.new.tap do |exc|
allow(exc).to receive(:generation).and_return(1234)
allow(exc).to receive(:service_id).and_return('fake')
end
end

it 'does not fail marking the server unknown' do
expect(error).to eq(exception)
end
end
end

context 'when #authenticate! raises an exception' do
Expand Down