Issue #265: "MySQL server has gone away" when running in embedded mode using MySQL (conservancy/kallithea)

freakrob issues-reply at bitbucket.org
Wed Jan 25 06:46:55 UTC 2017


New issue 265: "MySQL server has gone away" when running in embedded mode using MySQL
https://bitbucket.org/conservancy/kallithea/issues/265/mysql-server-has-gone-away-when-running-in

freakrob:

I recently updated from kallithea 0.3.1 to 0.3.2 -- in part due to the SQLite database having become corrupted. There was raw HTML put into the DB at some point...

Anyway, I installed a fresh copy of kallithea 0.3.2, followed the installation instructions, recovered a backup of the SQLite DB, converted it to MySQL and edited the my.ini according to my understanding.
The installation instructions now by default instruct one to run in mod_wsgi daemon mode.
So everything just worked after I had figured out how to convert the database and found the proper encoding.

Then, an issue with daemon mode and git push came up -- see #264 -- and I wanted to quickly change back to running in mod_wsgi embedded mode.
However, I could not use kallithea anymore, because the database connection to my MySQL db would time out and kallithea apparently doesn't try to reconnect in embedded mode.

Here's the log:

```
[Tue Jan 24 17:32:41.743620 2017] [wsgi:error] [pid 6796:tid 140172129711872] 2017-01-24 17:32:41.743 INFO  [kallithea.lib.auth_modules.auth_ldap] user USER_A authenticated correctly
[Tue Jan 24 17:32:41.942545 2017] [wsgi:error] [pid 6796:tid 140172129711872] 2017-01-24 17:32:41.942 INFO  [kallithea.lib.base] Access for IP:MY_IP allowed
[Tue Jan 24 17:32:42.047881 2017] [wsgi:error] [pid 6796:tid 140172129711872] 2017-01-24 17:32:42.047 INFO  [kallithea.lib.middleware.simplegit] push action on Git repo "REPO" by "USER_A" from MY_IP
[Tue Jan 24 17:32:42.089527 2017] [wsgi:error] [pid 6796:tid 140172129711872] 2017-01-24 17:32:42.089 INFO  [kallithea.RequestWrapper] IP: MY_IP Request to /REPO/git-receive-pack time: 0.608s
[Tue Jan 24 17:32:42.187430 2017] [wsgi:error] [pid 6796:tid 140172121319168] 2017-01-24 17:32:42.187 ERROR [kallithea.lib.middleware.simplegit] Traceback (most recent call last):
[Tue Jan 24 17:32:42.187453 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-0.3.2/kallithea/lib/middleware/simplegit.py", line 243, in __get_repository
[Tue Jan 24 17:32:42.187456 2017] [wsgi:error] [pid 6796:tid 140172121319168]     environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO'])
[Tue Jan 24 17:32:42.187458 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-0.3.2/kallithea/lib/base.py", line 202, in _get_by_id
[Tue Jan 24 17:32:42.187460 2017] [wsgi:error] [pid 6796:tid 140172121319168]     by_id_match = get_repo_by_id(repo_name)
[Tue Jan 24 17:32:42.187463 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-0.3.2/kallithea/lib/utils.py", line 145, in get_repo_by_id
[Tue Jan 24 17:32:42.187465 2017] [wsgi:error] [pid 6796:tid 140172121319168]     repo = Repository.get(_repo_id)
[Tue Jan 24 17:32:42.187467 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-0.3.2/kallithea/model/db.py", line 123, in get
[Tue Jan 24 17:32:42.187469 2017] [wsgi:error] [pid 6796:tid 140172121319168]     return cls.query().get(id_)
[Tue Jan 24 17:32:42.187471 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 775, in get
[Tue Jan 24 17:32:42.187473 2017] [wsgi:error] [pid 6796:tid 140172121319168]     return self._load_on_ident(key)
[Tue Jan 24 17:32:42.187475 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2514, in _load_on_ident
[Tue Jan 24 17:32:42.187477 2017] [wsgi:error] [pid 6796:tid 140172121319168]     return q.one()
[Tue Jan 24 17:32:42.187479 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2184, in one
[Tue Jan 24 17:32:42.187492 2017] [wsgi:error] [pid 6796:tid 140172121319168]     ret = list(self)
[Tue Jan 24 17:32:42.187494 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-0.3.2/kallithea/lib/caching_query.py", line 83, in __iter__
[Tue Jan 24 17:32:42.187496 2017] [wsgi:error] [pid 6796:tid 140172121319168]     return Query.__iter__(self)
[Tue Jan 24 17:32:42.187498 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2227, in __iter__
[Tue Jan 24 17:32:42.187500 2017] [wsgi:error] [pid 6796:tid 140172121319168]     return self._execute_and_instances(context)
[Tue Jan 24 17:32:42.187502 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2242, in _execute_and_instances
[Tue Jan 24 17:32:42.187505 2017] [wsgi:error] [pid 6796:tid 140172121319168]     result = conn.execute(querycontext.statement, self._params)
[Tue Jan 24 17:32:42.187507 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1449, in execute
[Tue Jan 24 17:32:42.187509 2017] [wsgi:error] [pid 6796:tid 140172121319168]     params)
[Tue Jan 24 17:32:42.187511 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1584, in _execute_clauseelement
[Tue Jan 24 17:32:42.187513 2017] [wsgi:error] [pid 6796:tid 140172121319168]     compiled_sql, distilled_params
[Tue Jan 24 17:32:42.187515 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1698, in _execute_context
[Tue Jan 24 17:32:42.187517 2017] [wsgi:error] [pid 6796:tid 140172121319168]     context)
[Tue Jan 24 17:32:42.187519 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1691, in _execute_context
[Tue Jan 24 17:32:42.187521 2017] [wsgi:error] [pid 6796:tid 140172121319168]     context)
[Tue Jan 24 17:32:42.187523 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 331, in do_execute
[Tue Jan 24 17:32:42.187525 2017] [wsgi:error] [pid 6796:tid 140172121319168]     cursor.execute(statement, parameters)
[Tue Jan 24 17:32:42.187527 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
[Tue Jan 24 17:32:42.187529 2017] [wsgi:error] [pid 6796:tid 140172121319168]     self.errorhandler(self, exc, value)
[Tue Jan 24 17:32:42.187531 2017] [wsgi:error] [pid 6796:tid 140172121319168]   File "/srv/kallithea-venv/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
[Tue Jan 24 17:32:42.187533 2017] [wsgi:error] [pid 6796:tid 140172121319168]     raise errorclass, errorvalue
[Tue Jan 24 17:32:42.187536 2017] [wsgi:error] [pid 6796:tid 140172121319168] OperationalError: (OperationalError) (2006, 'MySQL server has gone away') 'SELECT repositories.statistics AS repositories_statistics, repositories.downloads AS repositories_downloads, repositories.landing_revision AS repositories_landing_revision, repositories.locked AS repositories_locked, repositories.changeset_cache AS repositories_changeset_cache, repositories.repo_id AS repositories_repo_id, repositories.repo_name AS repositories_repo_name, repositories.repo_state AS repositories_repo_state, repositories.clone_uri AS repositories_clone_uri, repositories.repo_type AS repositories_repo_type, repositories.user_id AS repositories_user_id, repositories.private AS repositories_private, repositories.description AS repositories_description, repositories.created_on AS repositories_created_on, repositories.updated_on AS repositories_updated_on, repositories.enable_locking AS repositories_enable_locking, 
 reposito
 ries.fork_id AS repositories_fork_id, repositories.group_id AS repositories_group_id \\nFROM repositories \\nWHERE repositories.repo_id = %s' ('REPO_ID',)
[Tue Jan 24 17:32:42.187544 2017] [wsgi:error] [pid 6796:tid 140172121319168]
[Tue Jan 24 17:32:42.187845 2017] [wsgi:error] [pid 6796:tid 140172121319168] 2017-01-24 17:32:42.187 ERROR [kallithea.lib.middleware.simplegit] error extracting repo_name: OperationalError("(OperationalError) (2006, 'MySQL server has gone away')",)
[Tue Jan 24 17:32:42.188336 2017] [wsgi:error] [pid 6796:tid 140172121319168] 2017-01-24 17:32:42.188 INFO  [kallithea.RequestWrapper] IP: MY_IP Request to /_REPO_ID/git-receive-pack time: 0.019s
```

My my.ini looks as follows:


```
#########################################################
### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG    ###
#########################################################

# SQLITE [default]
#sqlalchemy.db1.url = sqlite:///%(here)s/kallithea.db?timeout=60

# POSTGRESQL
#sqlalchemy.db1.url = postgresql://user:pass@localhost/kallithea

# MySQL
sqlalchemy.db1.url = mysql://kallithea@localhost/kallithea?charset=utf8

# see sqlalchemy docs for others

sqlalchemy.db1.echo = false
sqlalchemy.db1.pool_recycle = 3600
sqlalchemy.db1.convert_unicode = true
```

I'm not sure if it's something in the my.ini I misconfigured or if my setup (MySQL DB + running in embedded mode) is just not a supported use case. In any way, the instructions for using MySQL as DB could be a little clearer for the less knowledgeable such as myself :D




More information about the kallithea-general mailing list