Skip to content
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