Project

General

Profile

Actions

Bug #9494

closed

Race condition in autoload of Digest::SHA256, etc.

Added by Conrad.Irwin (Conrad Irwin) about 10 years ago. Updated over 9 years ago.

Status:
Closed
Target version:
-
[ruby-core:60527]

Description

At the moment the digest extension uses const_missing to implement autoload. Unfortunately there's a race condition: another thread can run after the constant is defined, but before it is initialized. (http://git.io/YW3bbA)

There's a minimal test case here: http://git.io/5umBqQ — this was happening to us regularly in production because each sidekiq worker would race to create a hash.

The work around we have deployed is to require digest/sha2.so pre-emptively. And the attached patch does that.

An alternative solution would be to use autoload, but that is deprecated; or to change the way meta-data is stored for Digest classes so that it can be accessed immediately. There's no way to use a mutex inside const_missing to fix this, because the bug is that the constant becomes not-missing before it is fully defined.


Files

require-digest-upfront.patch (1006 Bytes) require-digest-upfront.patch Conrad.Irwin (Conrad Irwin), 02/06/2014 07:51 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0