Pylons / waitress

Waitress - A WSGI server for Python 3
https://docs.pylonsproject.org/projects/waitress/en/latest/
Other
1.44k stars 164 forks source link

waitress server stuck #406

Closed mohamedAlaaK closed 1 year ago

mohamedAlaaK commented 1 year ago

Hello,

We are using waitress on a production server that ran out of memory for sometime. During that time we had this error in the logs:

ERROR:waitress:uncaptured python exception, closing channel <waitress.channel.HTTPChannel connected xxx.xxx.xxx.xxx:xxx at 0xxxxxx> (<class 'MemoryError'>: [/usr/lib/python3.8/site-packages/waitress/wasyncore.py|read|104] [/usr/lib/python3.8/site-packages/waitress/wasyncore.py|handle_read_event|498] [/usr/lib/python3.8/site-packages/waitress/channel.py|handle_read|173] [/usr/lib/python3.8/site-packages/waitress/channel.py|received|209] [/usr/lib/python3.8/site-packages/waitress/parser.py|received|173] [/usr/lib/python3.8/site-packages/waitress/receiver.py|received|51] [/usr/lib/python3.8/site-packages/waitress/buffers.py|append|274] [/usr/lib/python3.8/site-packages/waitress/buffers.py|append|56])

We had another 7 similar errors due to the memory outage.

After the server was back to normal, the waitress service couldn't recover back and process any requests although the python app was still printing logs. So, we had to do a manual restart in order to work.

Unfortunately, we can't control the memory outage as it may occur because of any reason every several month. But we don't want the system to be completely stuck if the server goes out of memory temporarily.

Is there anything can be done to prevent waitress from being stuck ?

mmerickel commented 1 year ago

Waitress is a thread-based server - so it cannot kill individual requests that are misbehaving. They will impact the entire process, including waitress and other requests that are being handled. It's important with any WSGI app to be careful with resource usage. If you really can't control it then you probably want to look at something like gunicorn or uwsgi that have a special mode that can run a separate process for each request, but that comes with many limitations and uses a lot more system resources to run the separate processes.