From d58c230d5d06ea10aec63a1d434be6f956d56bf5 Mon Sep 17 00:00:00 2001 From: Rosa Gutierrez Date: Mon, 9 Sep 2024 17:19:15 +0200 Subject: [PATCH] Lock the process record before heartbeating To guard against race conditions of the record being deleted precisely then. --- lib/solid_queue/processes/registrable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/solid_queue/processes/registrable.rb b/lib/solid_queue/processes/registrable.rb index 9eddf20e..084e8faf 100644 --- a/lib/solid_queue/processes/registrable.rb +++ b/lib/solid_queue/processes/registrable.rb @@ -53,7 +53,7 @@ def stop_heartbeat end def heartbeat - process.reload.heartbeat + process.with_lock(&:heartbeat) rescue ActiveRecord::RecordNotFound self.process = nil wake_up