From 081888d1f65874713e38158178a8373f8357adc4 Mon Sep 17 00:00:00 2001 From: Raphael Maenle Date: Mon, 17 Aug 2020 13:21:33 +0200 Subject: [PATCH] uwsgi initialization uses the --lazy flag, to prevent connection overload as described in https://serverfault.com/questions/407612/error-2006-mysql-server-has-gone-away the uwsgi server usually forks its workers from the parent, which already has a connection open to the mysql database. So the new child typically inherits the same connection. Should both workers use the same connection at the same time, the server connection throws a '2006, server has gone away error'. The flag --lazy creates fresh forks for each child, each creating a new connection. This prevents the overload and after testing, the '2006' error seems to not be reproduceable. --- docker/calendarwatch/docker-entrypoint.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docker/calendarwatch/docker-entrypoint.sh b/docker/calendarwatch/docker-entrypoint.sh index 5bb2faa..b4fca56 100755 --- a/docker/calendarwatch/docker-entrypoint.sh +++ b/docker/calendarwatch/docker-entrypoint.sh @@ -1,5 +1,17 @@ #!/bin/sh cd /home/calendarwatch -uwsgi --ini wsgi.ini + +# use flasks own uwsgi server for debugging: +# export FLASK_APP=/home/calendarwatch/server.py +# python3 server.py + + +# the --lazy flag forks() a new instance of the server +# instead of forking from the parent and copying the same mysql +# connection. If you don't do that, then multiple forks will use +# the same connection at the same time, causing the server to throw +# a 'connection has gone away' error. +# more here: https://serverfault.com/questions/407612/error-2006-mysql-server-has-gone-away +uwsgi --ini wsgi.ini --lazy echo "server has been started"