salt icon indicating copy to clipboard operation
salt copied to clipboard

saltutil.kill_job breaks on a windows minion

Open soodr opened this issue 11 years ago • 8 comments

Master : 
(salt)-bash-4.1$ salt --versions-report
           Salt: 2015.2.0rc1
         Python: 2.7.8 (default, Sep 24 2014, 11:50:00)
         Jinja2: 2.7.3
       M2Crypto: 0.22
 msgpack-python: 0.4.6
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: 1.4.2
         PyYAML: 3.11
          ioflo: 1.2.1
          PyZMQ: 14.5.0
           RAET: 0.6.3
            ZMQ: 4.0.5
           Mako: 1.0.0

Minion :
C:\salt>salt-call --versions-report
           Salt: 2014.7.0
         Python: 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
         Jinja2: 2.7.1
       M2Crypto: 0.21.1
 msgpack-python: 0.4.2
   msgpack-pure: Not Installed
       pycrypto: 2.6
        libnacl: Not Installed
         PyYAML: 3.11
          ioflo: Not Installed
          PyZMQ: 14.1.1
           RAET: Not Installed
            ZMQ: 4.0.4
           Mako: Not Installed

(salt)-bash-4.1$ salt sandbox320-tssa-2 saltutil.kill_job 20150503132817579848

sandbox320-tssa-2:
    The minion function caused an exception: Traceback (most recent call last):
      File "salt/minion.py", line 1019, in _thread_return
      File "salt/modules/saltutil.py", line 578, in kill_job
    AttributeError: 'module' object has no attribute 'SIGKILL'

soodr avatar May 03 '15 14:05 soodr

Thanks for this report @soodr. I know that @twangboy fixed a lot of windows bugs in the newest release, 2014.7.5, though I am not sure if this is one of them or not. Do you think you'd be able to test this on the newer version and let us know if this still needs to be fixed?

rallytime avatar May 03 '15 16:05 rallytime

This seems like a dupe of https://github.com/saltstack/salt/issues/14150.

I'm wondering if killing a job via cmd.script will be possible with a forthcoming fix to this issue? (per @olliewalsh https://github.com/saltstack/salt/issues/14150#issuecomment-91042266). Would killing the job account for the particular child processes?

In the case of cmd.script running with shell=powershell I see a cmd.exe process is spawned that starts a powershell.exe process. I'm hoping it will be possible to wipe out the children.

trevor-h avatar May 06 '15 00:05 trevor-h

Threading in windows fails to pass the Process ID of the new process. Turning on Multi_Processing in the minion conf. You'll get a stack trace on start up, but the rest seems to work. Needs further testing.

twangboy avatar May 07 '15 23:05 twangboy

Threading in windows fails to pass the Process ID of the new process.

There isn't a new process, there's a new thread.

olliewalsh avatar May 10 '15 19:05 olliewalsh

But a new process is started with an associated process ID as well. You can watch it start using Process Explorer.

Turning on Multi-Processing will most likely be the fix for this issue. It works great on develop branch. It works fine on 2015.5 as well, but there is a stack trace when the minion starts.

twangboy avatar May 11 '15 14:05 twangboy

Multi-Processing currently works on the develop branch. I have verified that turning on Multi-Processing does fix this problem. You can turn on Multi-Processing in earlier branches, but there is a stack trace when the minion starts. The minion, however, seems to continue to function correctly in the tests I did. There are no plans to fix the stack trace in the earlier branches.

twangboy avatar May 11 '15 21:05 twangboy

I can confirm on 2014.7.2 turning on multi-processing indeed spawns a new salt-minion process and the job being executed becomes a child of that process.

This doesn't enable/fix the kill_job functionality, but a workaround I am using successfully can be found here: https://gist.github.com/trevor-h/18a56725789cbc8ae5dc#file-salt-kill-children

The above powershell script can be executed with cmd.script and the job id wanting to be killed as the only parameter. It will find the child of the returned pid and kill it. This seems to allow the salt-minion process responsible for the job to finish gracefully enough to report the output and cause no ill effect to other running jobs or minion stability.

In my limited testing I saw no issues with the minion when multi-processing is enabled.

trevor-h avatar May 12 '15 15:05 trevor-h

@trevor-h It's strange that it's not killing the job for you with multiprocessing turned on. I'm testing using the following: Win 2008r2 64 Salt Minion 2014.7.5 I'm testing using process explorer on the minion so I can see exactly what's going on with the processes. I start a job that will take a while to complete. The following will stay up for 10 min:

salt '<minion>' cmd.run 'timeout 600'

Then I look at the active jobs to make sure the right Process ID is showing up in the job. Without multiprocessing turned on it contains the PID of the python process that's running salt. With multiprocessing it shows the correct PID for the new process.

salt-run jobs.active

I check the number under Running with the PID shown in Process Explorer. They match. Then I kill the process with the following command:

salt 't*64' saltutil.kill_job 20150513133203131617

I can actually see the process disappear under process explorer, but the minion returns the following:

Minion did not return. [No response]

To ensure the job was killed I run salt-run jobs.active again and it comes back clean. Is there something I'm doing differently that mine is working and yours is not?

twangboy avatar May 13 '15 17:05 twangboy