kgi/db.py caches database connections for later re-use. This is good and necessary, but has the problem that it does not re-open the connections should they die due to timeouts. This wasn't a problem when emapps was running as CGIs, but now as a WSGI app, this causes problems.
The connection should be re-opened when it times out.