Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Aborting transactions in killed threads #752

Merged
merged 2 commits into from

2 participants

Chris Hanks Jeremy Evans
Chris Hanks

Hi Jeremy -

So, it turned out that the unfortunate issue where the status of a killed thread was "run" was introduced in Ruby 1.9 but fixed in Ruby 2.0. This means that on Ruby 2.0, 2.1, and recent versions of Rubinius we can use the safer 1.8 behavior of executing a rollback if the current thread's status is "aborting". The specs pass on every version of Ruby on my system:

rvm rubies

   jruby-1.7.5 [ x86_64 ]
   rbx-2.1.1 [ x86_64 ]
   rbx-2.2.1 [ x86_64 ]
   rbx-2.2.3 [ x86_64 ]
   ruby-1.8.7-p374 [ x86_64 ]
   ruby-1.9.3-p484 [ x86_64 ]
 * ruby-2.0.0-p247 [ x86_64 ]
=> ruby-2.1.0 [ x86_64 ]

I couldn't find the list of Rubies you test Sequel on - are there any others I should run?

Thanks!

Jeremy Evans
Owner

Thanks for the patch! This looks good to me, so as long as it passes the test suite, it will go in.

I currently test Sequel on ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1.0, jruby 1.7, and rbx 2.2, so you appear to have everything covered.

Jeremy Evans jeremyevans merged commit 5d09d72 into from
Chris Hanks chanks deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 27 deletions.
  1. +11 −26 lib/sequel/database/transactions.rb
  2. +1 −1  spec/core/database_spec.rb
37 lib/sequel/database/transactions.rb
View
@@ -216,32 +216,17 @@ def begin_transaction_sql
SQL_BEGIN
end
- if (! defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby' or RUBY_ENGINE == 'rbx') and RUBY_VERSION < '1.9'
- # :nocov:
- # Whether to commit the current transaction. On ruby 1.8 and rubinius,
- # Thread.current.status is checked because Thread#kill skips rescue
- # blocks (so exception would be nil), but the transaction should
- # still be rolled back.
- def commit_or_rollback_transaction(exception, conn, opts)
- if exception
- false
- else
- if Thread.current.status == 'aborting'
- rollback_transaction(conn, opts)
- false
- else
- commit_transaction(conn, opts)
- true
- end
- end
- end
- # :nocov:
- else
- # Whether to commit the current transaction. On ruby 1.9 and JRuby,
- # transactions will be committed if Thread#kill is used on an thread
- # that has a transaction open, and there isn't a work around.
- def commit_or_rollback_transaction(exception, conn, opts)
- if exception
+ # Whether to commit the current transaction. Thread.current.status is
+ # checked because Thread#kill skips rescue blocks (so exception would be
+ # nil), but the transaction should still be rolled back. On Ruby 1.9 (but
+ # not 1.8 or 2.0), the thread status will still be "run", so Thread#kill
+ # will erroneously commit the transaction, and there isn't a workaround.
+ def commit_or_rollback_transaction(exception, conn, opts)
+ if exception
+ false
+ else
+ if Thread.current.status == 'aborting'
+ rollback_transaction(conn, opts)
false
else
commit_transaction(conn, opts)
2  spec/core/database_spec.rb
View
@@ -825,7 +825,7 @@ def @db.ret_commit
@db.sqls.should == ['BEGIN', 'BEGIN -- test', 'DROP TABLE test;', 'COMMIT -- test', 'COMMIT']
end
- if (!defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby' or RUBY_ENGINE == 'rbx') and RUBY_VERSION < '1.9'
+ if (!defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby' or RUBY_ENGINE == 'rbx') and !RUBY_VERSION.start_with?('1.9')
specify "should handle Thread#kill for transactions inside threads" do
q = Queue.new
q1 = Queue.new
Something went wrong with that request. Please try again.