OperationalError: (OperationalError) (2006, 'MySQL server has gone away'

Issue #139 resolved
Marc Sanfaçon
created an issue

We're using Rhodecode with MySQL and when the system is idle for a certain time (in this case, all night), the first connection results in the following error:

{{{ ⇝ OperationalError: (OperationalError) (2006, 'MySQL server has gone away') 'SELECT users.user_id AS users_user_id, users.username AS users_username, users.password AS users_password, users.active AS users_active, users.admin AS users_admin, users.name AS users_name, users.lastname AS users_lastname, users.email AS users_email, users.last_login AS users_last_login, users.is_ldap AS users_is_ldap \nFROM users \nWHERE users.username = %s' ('default',) }}}

{{{ File '/usr/local/lib/python2.6/dist-packages/WebError-0.10.3-py2.6.egg/weberror/evalexception.py', line 431 in respond app_iter = self.application(environ, detect_start_response) File '/usr/local/lib/python2.6/dist-packages/RhodeCode-1.1.6-py2.6.egg/rhodecode/lib/middleware/simplegit.py', line 101 in call return self.application(environ, start_response) File '/usr/local/lib/python2.6/dist-packages/RhodeCode-1.1.6-py2.6.egg/rhodecode/lib/middleware/simplehg.py', line 67 in call return self.application(environ, start_response) File '/usr/local/lib/python2.6/dist-packages/Beaker-1.5.4-py2.6.egg/beaker/middleware.py', line 152 in call return self.wrap_app(environ, session_start_response) File '/usr/local/lib/python2.6/dist-packages/Routes-1.12.3-py2.6.egg/routes/middleware.py', line 131 in call response = self.app(environ, start_response) File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/wsgiapp.py', line 107 in call response = self.dispatch(controller, environ, start_response) File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/wsgiapp.py', line 312 in dispatch return controller(environ, start_response) File '/usr/local/lib/python2.6/dist-packages/RhodeCode-1.1.6-py2.6.egg/rhodecode/lib/base.py', line 49 in call self.rhodecode_user = c.rhodecode_user = auth.get_user(session) File '/usr/local/lib/python2.6/dist-packages/RhodeCode-1.1.6-py2.6.egg/rhodecode/lib/auth.py', line 325 in get_user anonymous_user = UserModel().get_by_username('default', cache=True) File '/usr/local/lib/python2.6/dist-packages/RhodeCode-1.1.6-py2.6.egg/rhodecode/model/user.py', line 63 in get_by_username return user.scalar() File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1677 in scalar ret = self.one() File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1646 in one ret = list(self) File '/usr/local/lib/python2.6/dist-packages/RhodeCode-1.1.6-py2.6.egg/rhodecode/model/caching_query.py', line 77 in iter return self.get_value(createfunc=lambda: list(Query.iter(self))) File '/usr/local/lib/python2.6/dist-packages/RhodeCode-1.1.6-py2.6.egg/rhodecode/model/caching_query.py', line 95 in get_value ret = cache.get_value(cache_key, createfunc=createfunc) File '/usr/local/lib/python2.6/dist-packages/Beaker-1.5.4-py2.6.egg/beaker/cache.py', line 214 in get return self._get_value(key, **kw).get_value() File '/usr/local/lib/python2.6/dist-packages/Beaker-1.5.4-py2.6.egg/beaker/container.py', line 298 in get_value v = self.createfunc() File '/usr/local/lib/python2.6/dist-packages/RhodeCode-1.1.6-py2.6.egg/rhodecode/model/caching_query.py', line 77 in <lambda> return self.get_value(createfunc=lambda: list(Query.iter(self))) File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1689 in iter return self._execute_and_instances(context) File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1694 in _execute_and_instances mapper=self._mapper_zero_or_none()) File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/session.py', line 720 in execute clause, params or {}) File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/base.py', line 1191 in execute params) File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/base.py', line 1271 in _execute_clauseelement return self.execute_context(context) File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/base.py', line 1302 in execute_context context.parameters[0], context=context) File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/base.py', line 1401 in _cursor_execute context) File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/base.py', line 1394 in _cursor_execute context) File '/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/default.py', line 299 in do_execute cursor.execute(statement, parameters) File '/usr/lib/pymodules/python2.6/MySQLdb/cursors.py', line 166 in execute self.errorhandler(self, exc, value) File '/usr/lib/pymodules/python2.6/MySQLdb/connections.py', line 35 in defaulterrorhandler raise errorclass, errorvalue OperationalError: (OperationalError) (2006, 'MySQL server has gone away') 'SELECT users.user_id AS users_user_id, users.username AS users_username, users.password AS users_password, users.active AS users_active, users.admin AS users_admin, users.name AS users_name, users.lastname AS users_lastname, users.email AS users_email, users.last_login AS users_last_login, users.is_ldap AS users_is_ldap \nFROM users \nWHERE users.username = %s' ('default',) }}}

Doing a refresh of the page will load the page normally.

Comments (3)

  1. Marcin Kuzminski repo owner

    Please uncomment

    sqlalchemy.db1.pool_recycle = 3600

    in the ini file.

    pool_recycle
        The length of time to keep connections open before recycling them. If not specified, the connections will stay open forever. This should be specified for MySQL in particular because servers typically close connections after eight hours, resulting in a “MySQL server has gone away” error.
    

    Regards

  2. Log in to comment