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
7 changes: 7 additions & 0 deletions lib/mongo/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,13 @@ def pin_to_connection(connection_global_id, connection: nil)
#
# @api private
def unpin(connection = nil)
# Idempotent: if there is no pinned state to clear, do nothing. Nested
# unpin_maybe handlers (e.g. in BulkWrite#execute_operation wrapping an
# OpMsg execution that already calls unpin_maybe in its own do_execute)
# can call this method twice for the same error; checking the connection
# back into the pool a second time would raise from the pool.
return if @pinned_server.nil? && @pinned_connection.nil? && @pinned_connection_global_id.nil?

@pinned_server = nil
@pinned_connection_global_id = nil
conn = connection || @pinned_connection
Expand Down
22 changes: 22 additions & 0 deletions spec/mongo/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,26 @@
session.session_id.should be_a(BSON::Document)
end
end

describe '#unpin' do
context 'when called twice with the same connection' do
# Nested unpin_maybe handlers in the bulk_write code path can trigger
# Session#unpin to be invoked twice for the same network error: once
# from Operation::Executable#do_execute and once from
# BulkWrite#execute_operation. The second call must be a no-op rather
# than raising "Trying to check in a connection which is not currently
# checked out" from the pool.
it 'does not raise on the second call' do
server = authorized_client.cluster.next_primary
server.with_connection do |connection|
session.pin_to_server(server)
session.unpin(connection)

expect do
session.unpin(connection)
end.not_to raise_error
end
end
end
end
end
7 changes: 3 additions & 4 deletions spec/runners/transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def define_transactions_spec_tests(test_paths, expectations_bson_types: true)
spec = Mongo::Transactions::Spec.new(file)

context(spec.description) do
define_spec_tests_with_requirements(spec) do |_req|
define_spec_tests_with_requirements(spec) do |req|
spec.tests(expectations_bson_types: expectations_bson_types).each do |test|
context(test.description) do
before(:all) do
Expand All @@ -38,9 +38,8 @@ def define_transactions_spec_tests(test_paths, expectations_bson_types: true)
skip 'Test does not specify multiple mongoses'
end
end
skip test.skip_reason

skip 'Requirements not satisfied'
skip test.skip_reason if test.skip_reason
skip 'Requirements not satisfied' unless req.satisfied?

test.setup_test
end
Expand Down
Loading