benoitc / gunicorn

gunicorn 'Green Unicorn' is a WSGI HTTP Server for UNIX, fast clients and sleepy applications.
http://www.gunicorn.org
Other
9.88k stars 1.76k forks source link

Preserve worker exit codes in worker class #3330

Closed tback closed 3 days ago

tback commented 3 days ago

It'd be really great if the exit code of workers could be preserved in the worker class. That way we could log unusual ones. My reason for asking for this is that I'm trying to find processes that have be targeted by the oom killer. Those receive exit code 137. Then I could define a child_exit funktion that log what happened:

def child_exit(_, worker):
        worker.log.info(f"Child Exit: Worker with PID {worker.pid} exited with code {worker.exit_code}.")
tback commented 3 days ago

I just noticed this should be logged already. Yet I don't see exit code 137 while I'm quite sure it happens. Will update (and hopefully close) in about two hours https://github.com/benoitc/gunicorn/blob/bacbf8aa5152b94e44aa5d2a94aeaf0318a85248/gunicorn/arbiter.py#L528

tback commented 3 days ago

Conclusion: Exit code 137 is not magically produced in case of an OOMKill. It's neither a clear indicator for it. Exit code 137 is the result of adding the number of the signal (9 for SIGKILL) and 128 (the base number for signal exits).