Skip to content

Commit

Permalink
Switch to openssl digests to fix threadsafety errors
Browse files Browse the repository at this point in the history
Digest is apparently not threadsafe and was causing errors in the specs:

`Digest::Base cannot be directly inherited in Ruby`

aws/aws-sdk-ruby#525
aws/aws-sdk-ruby#529
  • Loading branch information
alexdunae committed Apr 14, 2021
1 parent 9c85c6d commit bcaa209
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/acts_as_replaceable/acts_as_replaceable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'digest'
require 'openssl'
require 'timeout'

module ActsAsReplaceable
Expand Down Expand Up @@ -104,7 +104,7 @@ def self.lock_if(condition, *lock_args, &block)
# eg. In a multi-threaded environment, 'find_or_create' is prone to failure due to the possibility
# that the process is preempted between the 'find' and 'create' logic
def self.lock(record, timeout = 20)
lock_id = "ActsAsReplaceable/#{Digest::MD5.digest([match_conditions(record), insensitive_match_conditions(record)].inspect)}"
lock_id = "ActsAsReplaceable/#{OpenSSL::Digest::MD5.digest([match_conditions(record), insensitive_match_conditions(record)].inspect)}"
acquired = false

# Acquire the lock by atomically incrementing and returning the value to see if we're first
Expand Down

0 comments on commit bcaa209

Please sign in to comment.