FIX: automatically timeout long running image magick commands (#12670)

Previously certain images may lead to convert / identify to run for unreasonable
amounts of time

This adds a maximum amount of time these commands can run prior to forcing
them to stop
This commit is contained in:
Sam
2021-04-12 13:55:54 +10:00
committed by GitHub
parent b6337b72f1
commit 5deda5ef3e
6 changed files with 37 additions and 9 deletions

View File

@ -95,7 +95,13 @@ module Discourse
private
def execute_command(*command, failure_message: "", success_status_codes: [0], chdir: ".")
def execute_command(*command, timeout: nil, failure_message: "", success_status_codes: [0], chdir: ".")
if timeout
# will send a TERM after timeout
# will send a KILL after timeout * 2
command = ["timeout", "-k", "#{timeout.to_f * 2}", timeout.to_s] + command
end
stdout, stderr, status = Open3.capture3(*command, chdir: chdir)
if !status.exited? || !success_status_codes.include?(status.exitstatus)