unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.45k stars 691 forks source link

UWSGI alarms not executing on Docker Containers #2345

Open jesseinit opened 3 years ago

jesseinit commented 3 years ago

My issue is when HARAKIRI happens on a worker, the defined log-alarms and alarms don't get fired when running in a docker container. This works fine without docker(or at least my version).

requirements.txt

click==8.0.1
Flask==2.0.1
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
uWSGI==2.0.19.1
Werkzeug==2.0.1

app.py

from flask import Flask
from time import sleep

app = Flask(__name__)

@app.route("", methods=['GET'])
def index():
    while True:
        sleep(5)
        break
    return {}, 200

if __name__ == '__main__':
    app.run()

Dockerfile

FROM python:3.8-slim

WORKDIR /app

ENV VIRTUAL_ENV=/opt/venv

RUN python3 -m venv $VIRTUAL_ENV

RUN apt-get update && apt-get install -y build-essential

COPY requirements.txt ./requirements.txt

RUN pip install -r requirements.txt

COPY . .

CMD [ "uwsgi", "--ini", "uwsgi.ini"]

uswgi.ini

[uwsgi]
master=True
http = :7080
module = app:app
logto = ./log/uwsgi.log
harakiri=2 ; I have an endpoint in a flask app that sleeps for 5 seconds and that triggers this.
log-alarm = catch_harakiri HARAKIRI ON WORKER
alarm = catch_harakiri cmd: echo "A Subprocess called Me >>>"
harakiri-verbose = true
enable-threads = true
py-tracebacker=./log/traceback

Docker Logs Screenshot 2021-09-18 at 15 09 14

Non-Docker Logs Screenshot 2021-09-18 at 15 09 56

xrmx commented 3 years ago

Do you have libpcre in your container image?

0xtruly commented 3 years ago

This fixed the error RUN apt-get update && apt-get install -y build-essential libpcre3 libpcre3-dev

Sun Sep 19 08:57:47 2021 - *** HARAKIRI ON WORKER 1 (pid: 12, try: 1) ***
HARAKIRI: -- syscall> 23 0x0 0x0 0x0 0x0 0x7ffdfbc84100 0x0 0x7ffdfbc840b0 0x7fcc575a68b3
HARAKIRI: -- wchan> 0
*** uWSGI Python tracebacker output ***

thread_id = uWSGIWorker1Core0 filename = /usr/local/lib/python3.8/site-packages/flask/app.py lineno = 2088 function = __call__ line = return self.wsgi_app(environ, start_response)
thread_id = uWSGIWorker1Core0 filename = /usr/local/lib/python3.8/site-packages/flask/app.py lineno = 2070 function = wsgi_app line = response = self.full_dispatch_request()
thread_id = uWSGIWorker1Core0 filename = /usr/local/lib/python3.8/site-packages/flask/app.py lineno = 1513 function = full_dispatch_request line = rv = self.dispatch_request()
thread_id = uWSGIWorker1Core0 filename = /usr/local/lib/python3.8/site-packages/flask/app.py lineno = 1499 function = dispatch_request line = return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
thread_id = uWSGIWorker1Core0 filename = /app/./app.py lineno = 9 function = index line = sleep(5)

Sun Sep 19 08:57:47 2021 - HARAKIRI !!! worker 1 status !!!
Sun Sep 19 08:57:47 2021 - HARAKIRI [core 0] 172.17.0.1 - GET / since 1632041864
Sun Sep 19 08:57:47 2021 - HARAKIRI !!! end of worker 1 status !!!
DAMN ! worker 1 (pid: 12) died, killed by signal 9 :( trying respawn ...
Respawned uWSGI worker 1 (new pid: 254)
python tracebacker for worker 1 available on traceback1
A Subprocess called Me >>>
subprocess 256 exited with code 0