-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Make ClimateControl.modify re-entrant #24
Conversation
end | ||
end | ||
|
||
expect(foo).to eq('bar') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
it "is re-entrant" do | ||
foo = with_modified_env(FOO: 'foo') do | ||
with_modified_env(BAR: 'bar') do | ||
'bar' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@@ -111,6 +111,16 @@ | |||
expect(ENV["BAZ"]).to be_nil | |||
end | |||
|
|||
it "is re-entrant" do | |||
foo = with_modified_env(FOO: 'foo') do | |||
with_modified_env(BAR: 'bar') do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@@ -111,6 +111,16 @@ | |||
expect(ENV["BAZ"]).to be_nil | |||
end | |||
|
|||
it "is re-entrant" do | |||
foo = with_modified_env(FOO: 'foo') do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
0d1a9bd
to
28264ba
Compare
With the lock added in 0.4, it's no longer safe to nest calls `ClimateControl.modify`, which is actually a useful feature when e.g. using `ClimateControl` in RSpec `around { ... }` blocks. Doing so results in a deadlock (stack trace from the spec included in this commit): ``` 1) Climate control is re-entrant Failure/Error: ClimateControl.modify(options, &block) ThreadError: deadlock; recursive locking # ./lib/climate_control/modifier.rb:10:in `process' # ./lib/climate_control.rb:10:in `modify' # ./spec/acceptance/climate_control_spec.rb:131:in `with_modified_env' # ./spec/acceptance/climate_control_spec.rb:116:in `block (3 levels) in <top (required)>' # ./lib/climate_control/modifier.rb:31:in `call' # ./lib/climate_control/modifier.rb:31:in `run_block' # ./lib/climate_control/modifier.rb:13:in `block in process' # ./lib/climate_control/modifier.rb:10:in `process' # ./lib/climate_control.rb:10:in `modify' # ./spec/acceptance/climate_control_spec.rb:131:in `with_modified_env' # ./spec/acceptance/climate_control_spec.rb:115:in `block (2 levels) in <top (required)>' # ./spec/acceptance/climate_control_spec.rb:149:in `block (2 levels) in <top (required)>' ``` Since the lock is here to protect against different threads accessing ClimateControl at the same time, it's safe for a given thread to make any changes it wants to the environment as long as it holds the locks, which is what this patch does.
28264ba
to
7d96f38
Compare
@krallin This looks great. I did some testing on my own as well. Thanks for your contribution! |
With the lock added in 0.4, it's no longer safe to nest calls
ClimateControl.modify
, which is actually a useful feature when e.g.using
ClimateControl
in RSpecaround { ... }
blocks. Doing soresults in a deadlock (stack trace from the spec included in this
commit):
Since the lock is here to protect against different threads accessing
ClimateControl at the same time, it's safe for a given thread to make
any changes it wants to the environment as long as it holds the locks,
which is what this patch does.
There was a bit of discussion about re-entrancy in #11, but I don't think the fact that
ClimateControl
will deadlock when nesting calls in the absence of re-entrancy was addressed.Thanks!