Skip to content

Commit

Permalink
Abort when exception is raised during analysis
Browse files Browse the repository at this point in the history
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
  • Loading branch information
ABaldwinHunter committed Sep 29, 2016
1 parent 073c664 commit c4a5b9a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Expand Up @@ -29,4 +29,6 @@ USER app

ENV JAVA_OPTS="-XX:+UseParNewGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10"

ENV JAVA_OPTS="-XX:+UseParNewGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10
CMD ["/usr/src/app/bin/duplication"]
11 changes: 9 additions & 2 deletions lib/cc/engine/analyzers/file_thread_pool.rb
Expand Up @@ -16,8 +16,8 @@ def run(&block)
queue = build_queue
lock = Mutex.new

@workers = thread_count.times.map do
Thread.new do
@workers = Array.new(thread_count) do
with_thread_abortion do
while (item = next_item(queue, lock))
yield item
end
Expand Down Expand Up @@ -54,6 +54,13 @@ def thread_count
DEFAULT_CONCURRENCY
end
end

def with_thread_abortion
t = Thread.new do
yield
end
(t.abort_on_exception = true) && t
end
end
end
end
Expand Down
17 changes: 13 additions & 4 deletions spec/cc/engine/analyzers/file_thread_pool_spec.rb
Expand Up @@ -3,8 +3,9 @@

RSpec.describe CC::Engine::Analyzers::FileThreadPool do
describe "#run" do
let(:thread) { Thread.new {} }
it "uses default count of threads when concurrency is not specified" do
allow(Thread).to receive(:new)
allow(Thread).to receive(:new).and_return(thread)

pool = CC::Engine::Analyzers::FileThreadPool.new([])
pool.run {}
Expand All @@ -15,7 +16,7 @@
end

it "uses default concurrency when concurrency is over max" do
allow(Thread).to receive(:new)
allow(Thread).to receive(:new).and_return(thread)

run_pool_with_concurrency(
CC::Engine::Analyzers::FileThreadPool::DEFAULT_CONCURRENCY + 2
Expand All @@ -27,7 +28,7 @@
end

it "uses default concucurrency when concucurrency is under 1" do
allow(Thread).to receive(:new)
allow(Thread).to receive(:new).and_return(thread)

run_pool_with_concurrency(-2)

Expand All @@ -37,7 +38,7 @@
end

it "uses supplied concurrency when valid" do
allow(Thread).to receive(:new)
allow(Thread).to receive(:new).and_return(thread)

run_pool_with_concurrency(1)

Expand All @@ -57,6 +58,14 @@
expect(results).to include("321")
expect(results).to include("zyx")
end

it "aborts on a thread exception" do
allow(Thread).to receive(:new).and_return(thread)

run_pool_with_concurrency(1)

expect(thread.abort_on_exception).to eq(true)
end
end

def run_pool_with_concurrency(concurrency)
Expand Down

0 comments on commit c4a5b9a

Please sign in to comment.