Skip to content

Commit 60ec52f

Browse files
committed
Fix potential hang with parallelize: false
We were missing a case in `HookRunner#wait_for_slot` where if no slots were available we would infinite loop on the thread that "lost" if another thread took all the slots. This would result in the losing thread never releasing the mutex, preventing the winning thread from release the slots! Thus the hook run would never terminate. Fix by `wait`ing in the case where there are no slots available so we release the lock awaiting a signal. Fixes sds#476
1 parent f8cd206 commit 60ec52f

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Fix `forwarding to private method` warning on Ruby 2.4.x
66
* Update `childprocess` dependency to 0.6.x series
77
* Auto-sign configuration file when installing hooks for the first time
8+
* Fix potential hang when a hook's `parallelize` option was set to `false`
89

910
## 0.38.0
1011

lib/overcommit/hook_runner.rb

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def wait_for_slot(hook)
107107

108108
# Wait for a signal from another thread to try again
109109
@resource.wait(@lock)
110+
else
111+
# Otherwise there are not slots left, so just wait for signal
112+
@resource.wait(@lock)
110113
end
111114
end
112115
end

spec/integration/parallelize_spec.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper'
2+
require 'timeout'
3+
4+
describe 'running a hook with parallelism disabled' do
5+
subject { shell(%w[git commit --allow-empty -m Test]) }
6+
7+
let(:config) { <<-YML }
8+
CommitMsg:
9+
TrailingPeriod:
10+
enabled: true
11+
parallelize: false
12+
YML
13+
14+
around do |example|
15+
repo do
16+
File.open('.overcommit.yml', 'w') { |f| f.write(config) }
17+
`overcommit --install > #{File::NULL}`
18+
example.run
19+
end
20+
end
21+
22+
it 'does not hang' do
23+
Timeout.timeout(5) { subject }
24+
end
25+
end

0 commit comments

Comments
 (0)