salt icon indicating copy to clipboard operation
salt copied to clipboard

salt-call sporadically crashes on Windows (probably on other OS as well).

Open juso opened this issue 12 years ago • 28 comments

Log:

10/01/14 10:29:22,441 [salt.minion      ][DEBUG   ] Parsed kwargs: {'__pub_fun': 'state.highstate', '__pub_jid': '20140110102922441000', '__pub_pid': 2716, '__pub_tgt': 'salt-call'}
10/01/14 10:29:22,441 [salt.log.setup   ][ERROR   ] An un-handled exception was caught by salt's global exception handler:
UnpackValueError: 
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "__main__.py", line 128, in <module>
  File "__main__salt-call__.py", line 14, in <module>
  File "salt/scripts.py", line 77, in salt_call
  File "salt/cli/__init__.py", line 303, in run
  File "salt/cli/caller.py", line 135, in run
  File "salt/cli/caller.py", line 78, in call
  File "salt/modules/state.py", line 237, in highstate
  File "salt/modules/state.py", line 91, in running
  File "salt/modules/saltutil.py", line 365, in is_running
  File "salt/modules/saltutil.py", line 392, in running
  File "salt/payload.py", line 95, in loads
  File "_unpacker.pyx", line 119, in msgpack._unpacker.unpackb (msgpack/_unpacker.cpp:119)
UnpackValueError

After this issue experienced once, any attempts to sync state of the machine, by either calling 'salt' on the master or calling 'salt-call' locally on the minion, will fail with the same exception.

Deleting cache files in the location 'C:\salt\var\cache\salt\minion\proc' allows to sync states using either master 'salt' or local 'salt-call'.

juso avatar Jan 10 '14 14:01 juso

Reason for the crash is likely be in the salt-call functionality which takes care on cache files (reading) in the location 'C:\salt\var\cache\salt\minion\proc' (on windows, on linux obviously '/var/cache/salt/minion/proc'). salt-call writes some operational info in the cache files in the above location, which includes timestamped id of the cache file (e.g. '20140110132604599000'), state "type" (e.g. 'state.highstate') etc. One of the piece of the stored info is the pid (processID?). Some particular pids (e.g. 2568) in combination with the prior field (2 bytes, unidentified by me) constitute sequence '0D 0A', which in turn is 'CR LF', and with high probability it's wrongly interpreted by the cache file reading procedure (reading file as text file, rather than binary one), causing 'unpack' in msgpack to fail. Example of such a cache file: salt-call_cache_file_issue

Please find here https://dl.dropboxusercontent.com/u/26461510/salt-call_cache_files_-_working_and_crashing.zip examples of cache files, both working and crashing (so the described above pattern can be double checked.).

To fix the problem a correct handling of cr/lf should be done somewhere in the chain (unpack? else?).

juso avatar Jan 10 '14 14:01 juso

Natural workaround would be to check the return code of the salt-call and in case erroneous - delete cache files and re-run again, but the problem I face with is that salt-call somehow manage to generate ctrl-c upon completion, so the following command receive it and exits.

Don't ask me how this happen, no idea :) - confirmed by invoking salt-call in different ways:

  • in *.cmd files - receive 'Terminate batch job (Y/N)?'
  • in Powershell scripts - commands following 'salt-call' not executed. E.g. '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe "& @(gci c:\salt\salt-*.win-amd64\salt-call.exe)[-1].fullname state.highstate; write-host 'after salt-call completed'"' - the 'write-host' will never be invoked.

Until this issue fixed the post-install salt auto sync (via local salt-call) cannot be reliably performed, so it's pretty bad on my side as my deployment process then require manual intervention on few dozen machines.

juso avatar Jan 10 '14 14:01 juso

I'm wondering if we're properly casting the pid to a string before attempting to serialize it with msgpack

UtahDave avatar Jan 10 '14 16:01 UtahDave

Can you test with this new installer?
http://docs.saltstack.com/downloads/Salt-Minion-0.17.4-2-AMD64-Setup.exe

UtahDave avatar Jan 10 '14 22:01 UtahDave

Dave, copy/paste things from irc (not sure you are still online):

 UtahDave: somehow I always bump on the first run into the issue with cr/lf in the pid in the cache file, but once I deleted the cache files (in fact the whole dir), then it looks fine.
<juso> UtahDave: now it's almost complete (takes around 5 minutes), but all the usual suspects have been passed, no set_mode problems, no cache file problems - looks good
* wkf has quit (Quit: My MacBook Pro has gone to sleep. ZZZzzz…)
<juso> UtahDave: the thing with cr/lf in cache files could be related to running salt process almost always with the same pid on freshly installed windows, very unlucky then. It failes very often. If I try to run it afterwards, then it fails once in 5-10 times, but on fresh intall far too often.
<juso> UtahDave: now can confirm - all run well, no issues, appart from probably harmless things like
<juso> 10/01/14 23:35:15,317 [salt.loader      ][DEBUG   ] Failed to import module openstack_config, this is most likely NOT a problem:
<juso> Traceback (most recent call last):
<juso>   File "salt/loader.py", line 641, in gen_functions
<juso>   File "salt/modules/openstack_config.py", line 18, in <module>
<juso> ImportError: No module named pipes
<juso> 10/01/14 23:35:15,317 [salt.loader      ][DEBUG   ] Failed to import module cloud, this is most likely NOT a problem:
<juso> Traceback (most recent call last):
<juso>   File "salt/loader.py", line 641, in gen_functions
<juso>   File "salt/modules/cloud.py", line 11, in <module>
<juso>   File "salt/cloud/__init__.py", line 31, in <module>
<juso>   File "salt/utils/cloud.py", line 17, in <module>

In short - the issue with cr/lf in cache file still there, but other things (with permissions and set_mode) seem like fixed

juso avatar Jan 10 '14 23:01 juso

Dave, I tested the latest 0.17.4.3 build with the cache file which caused the 'cr/lf' crash in 0.17.4 (from here https://dl.dropboxusercontent.com/u/26461510/salt-call_cache_files_-_working_and_crashing.zip ) - and it still crashes in the same place. I assumed that format of the cache files hasn't changed and this way it's a reliable way to test this functionality, let me know otherwise.

juso avatar Jan 11 '14 14:01 juso

I'm sorry, this latest build was to fix all those other problems.

I can focus on this issue now On Jan 11, 2014 7:37 AM, "juso" [email protected] wrote:

Dave, I tested the latest 0.17.4.3 build with the cache file which caused the 'cr/lf' crash in 0.17.4 (from here https://dl.dropboxusercontent.com/u/26461510/salt-call_cache_files_-_working_and_crashing.zip) - and it still crashes in the same place. I assumed that format of the cache files hasn't changed and this way it's a reliable way to test this functionality, let me know otherwise.

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/9673#issuecomment-32097555 .

UtahDave avatar Jan 11 '14 17:01 UtahDave

@thatch45 do you have an idea what's going on here?

UtahDave avatar Jan 12 '14 06:01 UtahDave

@UtahDave, I bet it is a problem with how message pack is compiled into the windows installer, could we make an installer that uses the pure python msgpack_pure? It always works, regardless of underlying arch and compile aspects.

thatch45 avatar Jan 12 '14 06:01 thatch45

@thatch45 is that just a matter of pip installing msgpack_pure and removing the regular msgpack?

UtahDave avatar Jan 12 '14 06:01 UtahDave

Should be, these are really the kind of problems we see with msgpack on things like ARM systems and AIX, why not windows?

thatch45 avatar Jan 12 '14 06:01 thatch45

We have fixed it for Arm and Sparc, just for the record :)

thatch45 avatar Jan 12 '14 06:01 thatch45

OK, @juso I've built an installer that uses msgpack_pure instead of msgpack at @thatch45's suggestion.

Care to give this one a try? http://docs.saltstack.com/downloads/Salt-Minion-0.17.4-5-AMD64-Setup.exe

Thanks! I appreciate your patience and your willingness to test out all these builds. :)

UtahDave avatar Jan 12 '14 07:01 UtahDave

Dave, will do shortly. Did the format of the cache file changed? I.e. can I use known 'bad' cache files from previous installations? On Jan 12, 2014 8:57 AM, "David Boucha" [email protected] wrote:

OK, @juso https://github.com/juso I've built an installer that uses msgpack_pure instead of msgpack at @thatch45 https://github.com/thatch45's suggestion.

Care to give this one a try? http://docs.saltstack.com/downloads/Salt-Minion-0.17.4-5-AMD64-Setup.exe

Thanks! I appreciate your patience and your willingness to test out all these builds. :)

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/9673#issuecomment-32117454 .

juso avatar Jan 12 '14 08:01 juso

Dave, have tested the new build, no issues so far. I tested it both ways - naturally as installed and by placing known 'bad' cache files in the cache dir (of cause I don't know if the cache file format was preserved with your recent changes, but just in case gave it a try).

One thing I noticed - the behavior of cache files changed since last build, when previously cache file were getting accumulated in the cache dir until service restart, now cache file lives only for the duration of salt-call session, been deleted afterwards.

juso avatar Jan 12 '14 11:01 juso

One small thing, some failure, but probably not critical:

12/01/14 12:26:58,060 [salt.loader      ][DEBUG   ] Failed to import states pkg, this is most likely NOT a problem:
Traceback (most recent call last):
  File "salt/loader.py", line 641, in gen_functions
  File "salt/states/pkg.py", line 60, in <module>
ImportError: No module named msgpack

juso avatar Jan 12 '14 11:01 juso

What we did was install msgpack_pure instead of msgpack.

msgpack_pure is implemented in pure python instead of c , so it's cross platform, but a bit slower. The format of the cache didn't change

That error you saw is because I missed a msgpack import On Jan 12, 2014 4:31 AM, "juso" [email protected] wrote:

One small thing, some failure, but probably not critical:

12/01/14 12:26:58,060 [salt.loader ][DEBUG ] Failed to import states pkg, this is most likely NOT a problem: Traceback (most recent call last): File "salt/loader.py", line 641, in gen_functions File "salt/states/pkg.py", line 60, in ImportError: No module named msgpack

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/9673#issuecomment-32120370 .

UtahDave avatar Jan 12 '14 15:01 UtahDave

Great, thanx a lot Dave, will use this version until the next official one is out.

juso avatar Jan 12 '14 16:01 juso

@juso OK, here's another build that fixes the last error you ran into. http://docs.saltstack.com/downloads/Salt-Minion-0.17.4-6-AMD64-Setup.exe

UtahDave avatar Jan 12 '14 20:01 UtahDave

Dave, if you meant the log entry of msgpack import failure - then it's still there:

13/01/14 15:56:58,433 [salt.loader      ][DEBUG   ] Failed to import states pkg, this is most likely NOT a problem:
Traceback (most recent call last):
  File "salt/loader.py", line 641, in gen_functions
  File "salt/states/pkg.py", line 60, in <module>
ImportError: No module named msgpack

Though it's of lower prio, just distruct attention.

juso avatar Jan 13 '14 15:01 juso