Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ClimateControl.modify re-entrant
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.
- Loading branch information