diff --git a/app/services/job_processor.rb b/app/services/job_processor.rb index 8eed908b97..c7eab01cbf 100644 --- a/app/services/job_processor.rb +++ b/app/services/job_processor.rb @@ -3,9 +3,16 @@ # Forks into a separate process to contain memory usage and timeout errors. class JobProcessor def self.perform_forked(job, *args) - fork do + # Reports should abort when puma threads are killed to avoid wasting + # resources. Nobody would be collecting the result. We still need to + # implement a way to email or download reports later. + timeout = ENV.fetch("RACK_TIMEOUT_WAIT_TIMEOUT", "30").to_i + + child = fork do Process.setproctitle("Job worker #{job.job_id}") - job.perform(*args) + Timeout.timeout(timeout) do + job.perform(*args) + end # Exit is not a good idea within a Rails process but Rubocop doesn't know # that we are in a forked process. @@ -13,5 +20,9 @@ class JobProcessor end Process.waitall + ensure + # If this Puma thread is interrupted then we need to detach the child + # process to avoid it becoming a zombie. + Process.detach(child) end end