st2 icon indicating copy to clipboard operation
st2 copied to clipboard

Execution stuck in "Running" state

Open felin-arch opened this issue 11 years ago • 27 comments

I recently ran into a problem which caused the state of the execution to incorrectly report "Running". Looking at the logs, the actions clearly fails. There is no way to cancel it or remove it via the UI or the CLI. The action never seems to time out.

It happened when the result of the action contained some non-utf8 characters. I posted the action runner log at here.

Some background info: running stackstorm 0.11.6 on CentOS 7 with the latest python available on the OS.

I was able to reproduce this multiple times. The action should fail with the error message seen in the logs.

felin-arch avatar Jul 14 '15 10:07 felin-arch

I had the same on RHEL 6.4, st2 0.11.6 with errors in yaml files for certain actions. Though the task timed out eventually.

emptywee avatar Jul 14 '15 13:07 emptywee

Seen this once in a while but it was elusive enough that the RC was not obvious. The logs should help.

Btw, you can cancel the running execution with st2 execution cancel <execution_id>. It is not a proper cancel i.e. will not stop an execution which is actively performing an activity but would work well in this case where the RUNNIG state is incorrect.

http://docs.stackstorm.com/cli.html?highlight=cancel#cancel-an-execution

manasdk avatar Jul 14 '15 14:07 manasdk

@manasdk I did try to cancel it the way you described. Unfortunately it said the cancellation failed.

felin-arch avatar Jul 14 '15 19:07 felin-arch

Good to know. Will fix the root-cause anyway and work out why the cancel failed as well.

manasdk avatar Jul 14 '15 19:07 manasdk

@felin-arch: Looking at the code, we do set the action status as "failed" https://github.com/StackStorm/st2/blob/master/st2actions/st2actions/worker.py#L106

Are you able to repro this every time? Some more info about the script and the data will definitely help.

Regarding cancellation failing, we decided that canceling a simple action would mean different things based on the runner. So it's impossible to guarantee anything. So on cancelation, we check if the status is 'scheduled'. Only then we cancel. We are talking about this here but wanted to throw more context at you. In workflows, we stop at the action last running before cancelation and mark the workflow as canceled.

lakshmi-kannan avatar Jul 14 '15 20:07 lakshmi-kannan

I will try to set up a minimum environment for reproduction. Then I can test a few different ideas. I'll be back once that is done.

felin-arch avatar Jul 15 '15 20:07 felin-arch

I was not successful in isolating the problem in a minimal environment. Currently I am using st2 to run scheduled jobs and after a day of running it I always end up with more than 10 jobs stuck in running state. Needless to say the jobs are not actually running.

Running the jobs from the st2 UI also produces stuck jobs from time to time. It does not seem to make any difference. Running the script by hand is successful every single time.

All of these scripts are run on a remote machine. The command I tried by hand is the following:

ssh -tt [remote IP] "sudo su - [user] -c '/path/to/python/script.py'"

I upgraded to 0.12.0. The problem still exists. Some more info: When the job stucks in running mode it does not seem to start on the remote server at all. This will shift the focus to the initial part of the running process.

felin-arch avatar Jul 27 '15 07:07 felin-arch

@felin-arch Thanks for the report. We use st2 as our CI tool (dogfood) and we have several actions and workflows running (remote actions as well). We don't see this problem. I am thinking aloud to see how we can repro the problem you are seeing.

  1. Are you restarting st2 services at all or do you see this issue without any st2 restarts?

  2. Are these remote actions kicked off on multiple hosts in parallel?

  3. Do you see actions other than SSH actions getting stuck?

lakshmi-kannan avatar Jul 27 '15 23:07 lakshmi-kannan

@lakshmi-kannan Here is some more info on this:

  1. st2 services are not restarted only on st2 upgrades, otherwise only reload is called about once every two days.
  2. No, all these actions are kicked off on the same remote machine. However it may be possible, that the actions are started in parallel so multiple ssh connections should open.
  3. No, so far only remote SSH actions got stuck.

felin-arch avatar Jul 28 '15 07:07 felin-arch

@felin-arch lakshmi-kannan is out today so unlikely to get any progress on this today. It seems we may need a co-debug session. Possible that we can repro internally and may not need to bother you with the repro scenario. Possibly some movement on this tomorrow.

manasdk avatar Jul 28 '15 21:07 manasdk

@felin-arch: Might be related - https://github.com/StackStorm/st2/pull/1756. This could explain the problem with stuck actions however won't explain the behavior you see with cancel. Maybe as manas suggests, we can do a joint debug session sometime? I can do google hangout or skype. I'd really like to get to the bottom of this and get you unblocked.

lakshmi-kannan avatar Jul 29 '15 17:07 lakshmi-kannan

@lakshmi-kannan I was able to repro the original issue with

st2 run core.local cmd="python -c 'print \"\x82\"'"

logs -

2015-07-29 11:51:59,254 140615679969872 ERROR log [-] QueueConsumer failed to process message: LiveActionDB(action="core.local", callback={}, context={u'user': u'stanley'}, end_timestamp=None, id=55b920cf32ed352a9ca80dd2, notify=None, parameters={u'cmd': u'python -c \'print "\\x82"\''}, result={}, runner_info={}, start_timestamp="2015-07-29 18:51:59.041590+00:00", status="scheduled")
Traceback (most recent call last):
  File "/mnt/st2repos/st2/st2common/st2common/transport/consumers.py", line 59, in _process_message
    self._handler.process(body)
  File "/mnt/st2repos/st2/st2actions/st2actions/worker.py", line 98, in process
    result = self.container.dispatch(liveaction_db)
  File "/mnt/st2repos/st2/st2actions/st2actions/container/base.py", line 59, in dispatch
    liveaction_db = self._do_run(runner, runnertype_db, action_db, liveaction_db)
  File "/mnt/st2repos/st2/st2actions/st2actions/container/base.py", line 133, in _do_run
    result, context)
  File "/mnt/st2repos/st2/st2actions/st2actions/container/base.py", line 172, in _update_live_action_db
    liveaction_db=liveaction_db)
  File "/mnt/st2repos/st2/st2common/st2common/util/action_db.py", line 195, in update_liveaction_status
    liveaction_db = LiveAction.add_or_update(liveaction_db)
  File "/mnt/st2repos/st2/st2common/st2common/persistence/base.py", line 118, in add_or_update
    model_object = cls._get_impl().add_or_update(model_object)
  File "/mnt/st2repos/st2/st2common/st2common/models/db/__init__.py", line 134, in add_or_update
    instance.save()
  File "/mnt/st2repos/st2/virtualenv/local/lib/python2.7/site-packages/mongoengine/document.py", line 267, in save
    upsert=True, **write_concern)
  File "/mnt/st2repos/st2/virtualenv/local/lib/python2.7/site-packages/pymongo/collection.py", line 572, in update
    check_keys, self.uuid_subtype), safe)
InvalidStringData: strings in documents must be valid UTF-8: '\x82\n'

manasdk avatar Jul 29 '15 18:07 manasdk

@manasdk You did good with the repro :). See the WIP PR. cc: @felin-arch

lakshmi-kannan avatar Jul 29 '15 21:07 lakshmi-kannan

Hi guys,

I am sorry, it takes me ages to reply back on this. I was taken off the team which handles st2 :(. I rarely have time to check on it. I am going to ask a colleague about the join debug session. That sounds like something that could really speed things up.

In the mean time here is some more information (st2 ran for 5+ days unattended):

  • now it has 200+ running jobs
  • it also has more than 300 in "Requested" state (it seems like the 5 action runners are all stuck somehow)
  • not a single job succeeded in the last 2 days

I hope this may provide some more clue into what's going on.

I also upgraded to 12.1. It seems to be better regarding stuck jobs. I'll report back later about this.

felin-arch avatar Aug 03 '15 07:08 felin-arch

@felin-arch @lakshmi-kannan recently fixed one bug related to this issue - #1767. This and a couple of other changes were included in the v0.12.1 release (https://github.com/StackStorm/st2/blob/v0.12.1/CHANGELOG.rst#0121---july-31-2015).

There might be some other undiscovered issues left which are causing your problem, but it would still be great if you can try upgrading to this new release and see if it solves your problem.

Kami avatar Aug 03 '15 09:08 Kami

I did the upgrade. It all went fine for about 2 hours, then came the first job that stopped in a "Scheduled" state, than a few minutes later another stuck in "Running".

I think this might be related to parallel SSH executions as the linked post suggested. We are running multiple SSH jobs at the same time 3-4 on the same host. Thats where the problems start. I decreased the number of action processors to 1 to avoid any parallel executions. This may help point to the cause of this.

felin-arch avatar Aug 03 '15 09:08 felin-arch

Reducing the number of action runners did not help. After about 20 minutes I already see 2 jobs stuck in "Running". I do not even know how that is possible as there is only a single runner.

Finally I got something that might be useful in the logs. Here is the action runner log: st2actionrunner.PID.log

One more thing. I occasionally clean up "Running", "Scheduled" and "Requested" jobs from the DB since it is all a mess now. It may cause inconsistencies, however this cannot be the root cause as it only started after the stuck behaviour.

felin-arch avatar Aug 03 '15 10:08 felin-arch

@felin-arch Yeah, the issue could be related to the remote SSH runner. @lakshmi-kannan is working on a new and more robust remote SSH runner which should be ready in the near future (current one is based on fabric and we had tons of issues with it ourselves).

Also, thanks for the logs. We will have a look.

Kami avatar Aug 03 '15 10:08 Kami

@Kami Is there any chance that next-gen runner is in the development branch of st2? Then I will upgrade right away and check it out.

felin-arch avatar Aug 03 '15 10:08 felin-arch

@felin-arch I don't think it's that far yet, but I will let @lakshmi-kannan to post the update here when a branch with his changes is available.

Kami avatar Aug 03 '15 10:08 Kami