The flask app in question was working fine within Flask’s own development server. Whilst deploying the app, I ran into a 2 problems.
The first was a mismatch with apache2_mod_wsgi and the python3 version. It was throwing apache2 error messages of terminating threads. In order to fix this, I had to compile mod_wsgi from source, which was relatively easy from automated scripts, but had to install all of the necessary python headers and C compilers to tailor this to the system. No more errors but it seems to run indifferently nonetheless.
At first I thought the threading issue caused the sessions being randomly dropped, which didn’t happen in dev. Which leads me to the second problem.
Starting a session through the app (login), I can click on as many session related pages fine within a short space of time. If I stopped for more then 10 seconds, the session would drop and would prompt to log in… again.
After alot of debugging and hunting, I found the problem to be actually in apache2 config for the site. Within the .conf, the WSGI configuration was fine. However, the standard Apache document root folder directive was set 1 level above the app.wsgi file.
I’m not too clued up on the exact reason for this behaviour, but I think that when the Apache worker idles, there is insufficient permissions to read from the instance source (.wsgi file). This might kill the worker (& the app instance) and forget any sessions.
A relatively easy fix for a big problem.
P.s. if someone could explain this phenomenon better to me, please do so I can learn/update the post! Thanks.