Skip to content

Commit 853d256

Browse files
committed
Address FileThreadPool race condition
I saw a couple ThreadErrors around popping from an emtpy queue in bugsnag: this got introduced when I moved away from catching all ThreadErrors. There's a race condition between checking that the queue is empty & attempting to pop from it. This change locks the pop operation with a mutex to prevent the race.
1 parent 67b9919 commit 853d256

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/cc/engine/analyzers/file_thread_pool.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ def initialize(files, concurrency: DEFAULT_CONCURRENCY)
1414

1515
def run(&block)
1616
queue = build_queue
17+
lock = Mutex.new
1718

1819
@workers = thread_count.times.map do
1920
Thread.new do
20-
while !queue.empty? && (item = queue.pop(true))
21-
yield item
21+
while !queue.empty?
22+
item = lock.synchronize { queue.pop(true) if !queue.empty? }
23+
yield item if item
2224
end
2325
end
2426
end

0 commit comments

Comments
 (0)