Browse files

ensure freeze on Thread freezes locals

  • Loading branch information...
1 parent 230c606 commit ec1227a9cc682ebf796689ef0f329038162c421b @baroquebobcat baroquebobcat committed with guilleiguaran Aug 19, 2013
Showing with 14 additions and 0 deletions.
  1. +5 −0 activesupport/lib/active_support/core_ext/thread.rb
  2. +9 −0 activesupport/test/core_ext/thread_test.rb
View
5 activesupport/lib/active_support/core_ext/thread.rb
@@ -62,6 +62,11 @@ def thread_variable?(key)
_locals.has_key?(key.to_sym)
end
+ def freeze
+ _locals.freeze
+ super
+ end
+
private
def _locals
View
9 activesupport/test/core_ext/thread_test.rb
@@ -63,6 +63,15 @@ def test_thread_variable_frozen
end
end
+ def test_thread_variable_frozen_after_set
+ t = Thread.new { }.join
+ t.thread_variable_set :foo, "bar"
+ t.freeze
+ assert_raises(RuntimeError) do
+ t.thread_variable_set(:baz, "qux")
+ end
+ end
+
def test_thread_variable_security
t = Thread.new { sleep }

0 comments on commit ec1227a

Please sign in to comment.