Bug 1723632

Summary: When restarting foreman-tasks, long running tasks got forcefully killed after 20 seconds of wait.
Product: Red Hat Satellite Reporter: Hao Chang Yu <hyu>
Component: Tasks PluginAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED ERRATA QA Contact: Peter Ondrejka <pondrejk>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.5.0CC: aruzicka, inecas, pcreech
Target Milestone: 6.11.0Keywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-07-05 14:27:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Hao Chang Yu 2019-06-25 03:23:16 UTC
Description of problem:
In some cases, long running task like LOCE task and Katello Event Monitor task in a heavy loaded Satellite can get kill forcefully when restarting the foreman-tasks.

After restarting the foreman-tasks, these tasks will get invalidated and enter paused/error state due to Abnormal termanation like below.
---------------------------
6b764da1-7575-4b4b-a4ce-cb7b42bd8ae1,ForemanTasks::Task::DynflowTask,Actions::Candlepin::ListenOnCandlepinEvents,2019-06-23 07:53:31,,paused,error,97a1929c-1d6d-4ab2-a904-3338065334b0,,2019-06-23 07:53:31.69066

07:55:29.880357,118.021665403,87.6361777380003,0.5,1,Dynflow::ExecutionPlan::Steps::RunStep,"{""class"":""Dynflow::ExecutionPlan::Steps::Error"",""exception_class"":""StandardError"",""message"":""Abnormal termination (previous state: running)""
---------------------------


Dynflow wait for 20 seconds and then kill the executors if the tasks still haven't finished by that time.
---------------------------
Jun 24 14:33:09 my-satellite dynflowd: Dynflow Executor: stop in progress
Jun 24 14:33:09 my-satellite dynflowd: dynflow_executor: trying to stop process with pid 30687...
Jun 24 14:33:09 my-satellite dynflowd: dynflow_executor: trying to stop process with pid 30699...
Jun 24 14:33:29 my-satellite dynflowd: dynflow_executor: process with pid 30687 won't stop, we forcefully kill it...
Jun 24 14:33:29 my-satellite dynflowd: dynflow_executor: process with pid 30699 won't stop, we forcefully kill it...
---------------------------

Since that we are setting the systemd TimeoutSec to 90 seconds, Dynflow should also increase the "force_kill_waittime" of ruby daemon to some value below 90 seconds.e.g 60 seconds.

cat /usr/lib/systemd/system/dynflowd.service
[Service]
Type=forking
User=foreman
TimeoutSec=90      <======================= Systemd timeout
WorkingDirectory=/usr/share/foreman
ExecStart=/usr/sbin/dynflowd start
ExecStop=/usr/sbin/dynflowd stop
EnvironmentFile=-/etc/sysconfig/dynflowd


daemons-1.2.3/lib/daemons/application.rb
    def initialize(group, add_options = {}, pid = nil)
      @group = group
      @options = group.options.dup
      @options.update(add_options)

      @dir_mode = @dir = @script = nil

      @force_kill_waittime = @options[:force_kill_waittime] || 20 <========== Default 20 seconds



Suggest to make the "force_kill_waittime" an option in Dynflow so that user can adjust it.

Comment 4 Hao Chang Yu 2019-06-25 11:07:29 UTC
*** Bug 1723631 has been marked as a duplicate of this bug. ***

Comment 5 Eric Helms 2021-11-04 13:15:44 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/27123 has been resolved.

Comment 6 Peter Ondrejka 2022-02-11 12:24:46 UTC
Verified on Satellite 7.0 snap 8, the force_kill_waittime option has been added with default 60 and is adjustable

Comment 9 errata-xmlrpc 2022-07-05 14:27:54 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: Satellite 6.11 Release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:5498