Skip to content

Instantly share code, notes, and snippets.

@dwbutler
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwbutler/2c5bc4b7f05e5f7ecfd9 to your computer and use it in GitHub Desktop.
Save dwbutler/2c5bc4b7f05e5f7ecfd9 to your computer and use it in GitHub Desktop.
ActiveSupport's class_attribute is not thread-safe
# This is a script that reproduces https://github.com/rails/rails/issues/14021
require 'active_support/all'
ActiveSupport::VERSION::STRING
# => "4.1.1"
RUBY_ENGINE
# => "jruby"
class Foo
class_attribute :bar
end
Thread.abort_on_exception = true
(1..100).map do |i|
Thread.new do
Foo.bar = i
end
end
# NameError: Undefined method bar for 'Foo'
# from org/jruby/RubyModule.java:2297:in `undef_method'
# from /Users/dwbutler/.rvm/gems/jruby-1.7.12/gems/activesupport-4.1.1/lib/active_support/core_ext/module/remove_method.rb:4:in `remove_possible_method'
# from /Users/dwbutler/.rvm/gems/jruby-1.7.12/gems/activesupport-4.1.1/lib/active_support/core_ext/class/attribute.rb:85:in `bar='
# from org/jruby/RubyModule.java:2304:in `module_eval'
# from /Users/dwbutler/.rvm/gems/jruby-1.7.12/gems/activesupport-4.1.1/lib/active_support/core_ext/class/attribute.rb:84:in `bar='
# from (irb):21:in `evaluate'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment