Skip to content

Commit

Permalink
Use connection#quote instead of sanitize to avoid deadlock on 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Griffin committed Oct 23, 2012
1 parent 7300651 commit 1ca2438
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/mysql_mutex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class MySQLMutex < DistributedMutex

def initialize(key, timeout = DEFAULT_TIMEOUT, exception_on_timeout = DEFAULT_EXCEPTION_ON_TIMEOUT, connection = ActiveRecord::Base.connection)
super(key, timeout, exception_on_timeout)
@connection = connection
@connection_id = connection.show_variable('pseudo_thread_id')
@get_sql = ActiveRecord::Base.send(:sanitize_sql_array,["SELECT GET_LOCK(?,?)", key, timeout])
@release_sql = ActiveRecord::Base.send(:sanitize_sql_array,["SELECT RELEASE_LOCK(?)", key])
sanitized_key = connection.quote(key)
sanitized_timeout = connection.quote(timeout)
@connection = connection
@connection_id = connection.show_variable('pseudo_thread_id')
@get_sql = "SELECT GET_LOCK(#{sanitized_key},#{sanitized_timeout})"
@release_sql = "SELECT RELEASE_LOCK(#{sanitized_key})"
end

def self.synchronize(key, timeout = DEFAULT_TIMEOUT, exception_on_timeout = DEFAULT_TIMEOUT, con = ActiveRecord::Base.connection, &block)
Expand Down

0 comments on commit 1ca2438

Please sign in to comment.