salt icon indicating copy to clipboard operation
salt copied to clipboard

Input/output error when do not redirect output FD's

Open ghost opened this issue 13 years ago • 14 comments

I've found a lot of open issues on github/saltstack related to this code:

A normal daemonization redirects the process output to /dev/null.

Unfortunately when a python multiprocess is called the output is

not cleanly redirected and the parent process dies when the

multiprocessing process attempts to access stdout or err.

#dev_null = open('/dev/null', 'rw') #os.dup2(dev_null.fileno(), sys.stdin.fileno()) #os.dup2(dev_null.fileno(), sys.stdout.fileno()) #os.dup2(dev_null.fileno(), sys.stderr.fileno())

but have not found clear description of consequences. I already mentioned this issue in #5199.

Let's say I logged to SSH and restarted some salt process (master, minion or api) and logged out. Processes have not changed its output FD's and since my pts doesn't exist anymore (deleted after SSH stopped) we got:

salt-master 32288 root 0u CHR 136,2 0t0 4 /dev/pts/2 (deleted) salt-master 32288 root 1u CHR 136,2 0t0 4 /dev/pts/2 (deleted) salt-master 32288 root 2u CHR 136,2 0t0 4 /dev/pts/2 (deleted)

Then when this process (master, minion or api) put output to stdout or err, we got

salt-api output: write(1, "127.0.0.1 - - [24/Jun/2013:12:41:43] "GET /jobs/20130624124143585565 HTTP/1.1" 500 57 "" ""\n", 92) = -1 EIO (Input/output error)

minion output: 2013-05-22 15:31:33,433 [salt.minion ][ERROR ] Exception [Errno 5] Input/output error occurred in scheduled job

and the same happens to master.

The way to workaround this - start/restart processes from server console.

I'd like @basepi and @whiteinge (as we told on IRC) to take a look at this. I realize that this cannot be fixed as 1+1, but should be aware of.

ghost avatar Jun 24 '13 13:06 ghost

Thanks for the report. We'll look into it.

basepi avatar Jun 24 '13 17:06 basepi

Reassigning to @thatch45. Looks like there's a fair bit of history here (#1096 & #1831 at least) and I'm not sure where to start. This problem is intermittent but will leave both salt-api and the minion unresponsive when it crashes.

whiteinge avatar Jul 11 '13 21:07 whiteinge

We may also have seen this error triggered from a runner module that leaves the master unresponsive.

whiteinge avatar Jul 11 '13 21:07 whiteinge

Hi,

The " i/o error" issue is seen frequently in my salt setup. please take this as high priority and give us a fix.

Thanks, -Siva

sbusa avatar Sep 23 '13 22:09 sbusa

This is fairly high on our priority list, but it seems like there's always something else to distract.

Also realize that we have paying customers, and that's where our highest priority will always be.

basepi avatar Sep 23 '13 23:09 basepi

Let's me add my workaround. Im starting/restarting salt-master/salt-api in "screen", then just detach from "screen". This keeps processes shells alive all the time.

screen /etc/init.d/salt-master start CTRL+a+d - to detach screen -r - to resume the shell

aleksmm avatar Sep 24 '13 07:09 aleksmm

Hi,

Can you please let us know whether the fix for this issue will be available for upcoming releases?. This i/o error is easily reproducible in my setup. I restart the salt-master manually when this issue comes as the workaround mentioned with 'screen' didn't help.

Any update on this would be of great help.

Regards, -Siva

sbusa avatar Oct 21 '13 21:10 sbusa

Siva, please add more details about the issue you faced. "screen" workaround must help if you run properly,

aleksmm avatar Oct 21 '13 21:10 aleksmm

Okay, sure. Let me double-check and come back on this.

Thanks for the reply.

sbusa avatar Oct 22 '13 01:10 sbusa

Hi Aleks, I followed the same procedure, this time we did it in console -

screen /etc/init.d/salt-master start CTRL+a+d - to detach

This just happened, it looks like one of the salt-master's has become defunct.

18665 ? Ssl 0:33 /usr/bin/python /usr/bin/salt-master 18695 ? S 2:57 /usr/bin/python /usr/bin/salt-master 18702 ? Z 0:03 [salt-master] 18703 ? Sl 0:03 /usr/bin/python /usr/bin/salt-master 18706 ? Sl 0:34 /usr/bin/python /usr/bin/salt-master 18707 ? Sl 0:35 /usr/bin/python /usr/bin/salt-master 18710 ? Sl 0:35 /usr/bin/python /usr/bin/salt-master 18711 ? Sl 0:34 /usr/bin/python /usr/bin/salt-master 18716 ? Sl 0:36 /usr/bin/python /usr/bin/salt-master

Logs when a command is issued via salt cherrypy :

127.0.0.1 - - [23/Oct/2013:06:16:48] "POST / HTTP/1.1" 200 372 "" "Python-httplib2/0.7.2 (gzip)" 127.0.0.1 - - [23/Oct/2013:06:16:58] "POST / HTTP/1.1" 200 16 "" "Python-httplib2/0.7.2 (gzip)" 127.0.0.1 - - [23/Oct/2013:06:17:59] "POST / HTTP/1.1" 500 1828 "" "Python-httplib2/0.7.2 (gzip)" 127.0.0.1 - - [23/Oct/2013:06:18:59] "POST / HTTP/1.1" 500 1828 "" "Python-httplib2/0.7.2 (gzip)" 127.0.0.1 - - [23/Oct/2013:06:19:59] "POST / HTTP/1.1" 500 1828 "" "Python-httplib2/0.7.2 (gzip)" 127.0.0.1 - - [23/Oct/2013:06:20:59] "POST / HTTP/1.1" 500 1828 "" "Python-httplib2/0.7.2 (gzip)" 127.0.0.1 - - [23/Oct/2013:06:21:59] "POST / HTTP/1.1" 500 1828 "" "Python-httplib2/0.7.2 (gzip)" 127.0.0.1 - - [23/Oct/2013:06:22:59] "POST / HTTP/1.1" 500 1828 "" "Python-httplib2/0.7.2 (gzip)" 127.0.0.1 - - [23/Oct/2013:06:23:59] "POST / HTTP/1.1" 500 1828 "" "Python-httplib2/0.7.2 (gzip)" [23/Oct/2013:06:23:59] Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/cherrypy/_cpwsgi.py", line 169, in trap return func(_args, *_kwargs) File "/usr/lib/python2.7/dist-packages/cherrypy/_cpwsgi.py", line 96, in call return self.nextapp(environ, start_response) File "/usr/lib/python2.7/dist-packages/cherrypy/_cpwsgi.py", line 379, in tail return self.response_class(environ, start_response, self.cpapp) File "/usr/lib/python2.7/dist-packages/cherrypy/_cpwsgi.py", line 222, in init self.run() File "/usr/lib/python2.7/dist-packages/cherrypy/_cpwsgi.py", line 320, in run request.run(meth, path, qs, rproto, headers, rfile) File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 603, in run raise cherrypy.TimeoutError() TimeoutError

Thanks, -Siva

sbusa avatar Oct 23 '13 09:10 sbusa

Don't think that that traceback is somehow related to original issue. I think its wrong configuration causing TimeoutError

To check if your issue is related to original issue, run whit command and post its output:

  1. Find salt-master PID ps auxfww | grep salt-master

replace MASTER_PID with found PID 2) lsof -n -p MASTER_PID

aleksmm avatar Oct 24 '13 10:10 aleksmm

@sashkaua Can you check if this problem still persists on salt-api 0.8.3?

whiteinge avatar Dec 24 '13 03:12 whiteinge

@whiteinge it seems to be fixed, I see proper redirect of std* set in code:

/usr/lib/python2.6/site-packages/salt/utils/init.py: os.dup2(dev_null.fileno(), sys.stdin.fileno()) /usr/lib/python2.6/site-packages/salt/utils/init.py: os.dup2(dev_null.fileno(), sys.stdout.fileno()) /usr/lib/python2.6/site-packages/salt/utils/init.py: os.dup2(dev_null.fileno(), sys.stderr.fileno())

This gives:

salt-api 17803 root 0w CHR 1,3 0t0 1067 /dev/null salt-api 17803 root 1w CHR 1,3 0t0 1067 /dev/null salt-api 17803 root 2w CHR 1,3 0t0 1067 /dev/null

so, I think this issue can be marked as solved

aleksmm avatar Dec 24 '13 18:12 aleksmm

Thank you for checking!

whiteinge avatar Dec 24 '13 23:12 whiteinge