Skip to content

Commit ae69744

Browse files
steinybotsds
authored andcommitted
Bug/650 traceback when setting parallelize to false (#656)
* Reproduce deadlock when parallize is false * Fix potential deadlock when waiting for hooks If a hook is running while another hook tries to start and there are not enough slots left then it will wait for the first hook to stop and release its slots. This first hook will not signal the second if there are no more hooks left. This results in a deadlock. This situation is far more likely to occur when parallelize is false since the hook will consume all the available slots.
1 parent 0bc5531 commit ae69744

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Add `RubySyntax` pre-commit hook
77
* Relax `childprocess` dependency to allow version 1.x
88
* Add `CodeSpellCheck` pre-commit hook
9+
* Fix deadlock which was more likely to occur when setting `parallelize` on a hook to `false`
910

1011
## 0.48.1
1112

lib/overcommit/hook_runner.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,9 @@ def release_slot(hook)
129129
slots_released = processors_for_hook(hook)
130130
@slots_available += slots_released
131131

132-
if @hooks_left.any?
133-
# Signal once. `wait_for_slot` will perform additional signals if
134-
# there are still slots available. This prevents us from sending out
135-
# useless signals
136-
@resource.signal
137-
end
132+
# Signal every time in case there are threads that are already waiting for
133+
# these slots to be released
134+
@resource.signal
138135
end
139136
end
140137

spec/integration/parallelize_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
subject { shell(%w[git commit --allow-empty -m Test]) }
88

99
let(:config) { <<-YML }
10+
concurrency: 20
1011
CommitMsg:
1112
TrailingPeriod:
1213
enabled: true
1314
parallelize: false
15+
command: ['ruby', '-e', 'sleep 1']
16+
TextWidth:
17+
enabled: true
18+
parallelize: true
19+
processors: 1
1420
YML
1521

1622
around do |example|
@@ -22,6 +28,7 @@
2228
end
2329

2430
it 'does not hang' do
25-
Timeout.timeout(5) { subject }
31+
result = Timeout.timeout(5) { subject }
32+
result.stderr.should_not include 'No live threads left. Deadlock?'
2633
end
2734
end

0 commit comments

Comments
 (0)