Database settings in Zine
While browsing through the zine tickets looking for something to fix, I came across this ticket. Apparently, after a period of inactivity, the database connection was closed and zine did not notice. To gain some more visibility, I’ll post my comment on the bug here, too.
The error
The error reported was:
OperationalError: (OperationalError) server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.
It is not a bug
This is not a bug. This is intended behavior although maybe unexpected; as far as I know this is typical for MySQL. MySQL has a setting to close connections to the database which have been idle for a specified time. This might make sense to regain some of the resources which a buggy application might have forgotten about. But by default, SQLAlchemy does not expect this.
But it has a solution for it: pool_recycle. This setting sets a maximum time for each connection to reside in the connection pool. So with this, one can circumvent the timeout problem.
But how do we do this in zine?
Database Settings in Zine
In zine/database.py it says:
# alternative pool sizes / recycle settings and more. These are # interpreter wide and not from the config for the following reasons: # # - system administrators can set it independently from the webserver # configuration via SetEnv and friends. # - this setting is deployment dependent should not affect a development # server for the same instance or a development shell
So the zine creators chose to not use a config option for this but rather an environment variable. Reasons see above.
So for setting database specific things, set the environment variables
- ZINE_DATABASE_POOL_SIZE
- ZINE_DATABASE_POOL_RECYCLE
- ZINE_DATABASE_POOL_TIMEOUT
In the case of the problem mentioned, ZINE_DATABASE_POOL_RECYCLE is the appropriate action.
as101 Nov 9, 2009 3:52:00 AM | Permalink - Reply
Great article . Will definitely apply it to my blog.Thanks.