diff --git a/lib/concurrent-ruby/concurrent/tvar.rb b/lib/concurrent-ruby/concurrent/tvar.rb index 5d02ef090..b74417d7d 100644 --- a/lib/concurrent-ruby/concurrent/tvar.rb +++ b/lib/concurrent-ruby/concurrent/tvar.rb @@ -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 diff --git a/spec/concurrent/tvar_spec.rb b/spec/concurrent/tvar_spec.rb index 437ff5788..d1a2e3318 100644 --- a/spec/concurrent/tvar_spec.rb +++ b/spec/concurrent/tvar_spec.rb @@ -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