From dfb923e6e52d1fed768672b5b7e6277a599f136a Mon Sep 17 00:00:00 2001 From: Nick Howard Date: Mon, 19 Aug 2013 12:39:40 -0600 Subject: ensure freeze on Thread freezes locals --- activesupport/lib/active_support/core_ext/thread.rb | 5 +++++ activesupport/test/core_ext/thread_test.rb | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/thread.rb b/activesupport/lib/active_support/core_ext/thread.rb index 878ec73ef0..e80f442973 100644 --- a/activesupport/lib/active_support/core_ext/thread.rb +++ b/activesupport/lib/active_support/core_ext/thread.rb @@ -62,6 +62,11 @@ class Thread _locals.has_key?(key.to_sym) end + def freeze + _locals.freeze + super + end + private def _locals diff --git a/activesupport/test/core_ext/thread_test.rb b/activesupport/test/core_ext/thread_test.rb index 230c1203ad..cf1b48d511 100644 --- a/activesupport/test/core_ext/thread_test.rb +++ b/activesupport/test/core_ext/thread_test.rb @@ -63,6 +63,15 @@ class ThreadExt < ActiveSupport::TestCase 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 } -- cgit v1.2.3