Skip to content
Open
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: 2 additions & 2 deletions lib/concurrent-ruby/concurrent/tvar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def atomically
rescue Transaction::LeaveError => e
transaction.abort
break result
rescue => e
rescue Exception
transaction.abort
raise e
raise
end
# If we can commit, break out of the loop

Expand Down
16 changes: 16 additions & 0 deletions spec/concurrent/tvar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ module Concurrent
}.to raise_error(StandardError, 'This is an error!')
end

it 'aborts and releases locks for exceptions outside StandardError' do
t = TVar.new(0)
error = Interrupt.new('This is an interrupt!')

expect {
Concurrent::atomically do
t.value = 1
raise error
end
}.to raise_error(error)

expect(t.value).to eq 0
expect { Concurrent::atomically { t.value = 2 } }.not_to raise_error
expect(t.value).to eq 2
end

it 'retries on abort' do
count = 0

Expand Down