From 02927f509eb862096dd5094c69819a512aa774f3 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Mon, 3 Aug 2026 19:26:02 -0500 Subject: [PATCH] Don't use a shared closure for each spawned thread I identified a memory leak in a long-running Rails app using OkComputer and found it only triggered when `check_in_parallel` was `true`. Codex found the bug, but I authored the patch myself based on its analysis. I did not accept its initial suggestion. --- CHANGELOG.markdown | 2 ++ lib/ok_computer/check_collection.rb | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 05fb7c29..900e234d 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,4 +1,6 @@ #### Unreleased +* Don't use a shared closure for each spawned thread + > awilfox: https://github.com/okcomputer-ruby/okcomputer/pull/27 * Add SolidQueue checks: `SolidQueueCheck` (liveness + job stats), `SolidQueueBackedUpCheck` (per-queue backlog), `SolidQueueFailedJobsCheck` (total failed jobs), `SolidQueueFailedJobsRateCheck` (rapid increase in diff --git a/lib/ok_computer/check_collection.rb b/lib/ok_computer/check_collection.rb index 21d403fe..4073733c 100644 --- a/lib/ok_computer/check_collection.rb +++ b/lib/ok_computer/check_collection.rb @@ -113,10 +113,7 @@ def check_in_sequence end def check_in_parallel - threads = checks.map do |check| - Thread.new { check.run } - end - threads.each(&:join) + checks.map{ |check| Thread.new(check, &:run) }.each(&:join) end end end