Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure freeze on Thread freezes locals (#11831) #11940

Merged
merged 1 commit into from
Aug 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions activesupport/lib/active_support/core_ext/thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def thread_variable?(key)
_locals.has_key?(key.to_sym)
end

def freeze
_locals.freeze
super
end

private

def _locals
Expand Down
9 changes: 9 additions & 0 deletions activesupport/test/core_ext/thread_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down