Occasional erros in the mysql driver

Bug #1808381 reported by Alexandru Sorodoc
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tooz
New
Undecided
Unassigned

Bug Description

Hello,

We are getting the following error in gnocchi:

2018-12-13 10:01:05,723 [3173] ERROR cotyledon._utils: Unhandled exception
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cotyledon/_utils.py", line 84, in exit_on_exception
    yield
  File "/usr/lib/python2.7/site-packages/cotyledon/_service.py", line 139, in _run
    self.run()
  File "/usr/lib/python2.7/site-packages/gnocchi/cli.py", line 137, in run
    self._run_job()
  File "/usr/lib/python2.7/site-packages/gnocchi/cli.py", line 261, in _run_job
    lock.release()
  File "/usr/lib/python2.7/site-packages/tooz/drivers/mysql.py", line 102, in release
    cause=e)
  File "/usr/lib/python2.7/site-packages/tooz/utils.py", line 225, in raise_with_cause
    excutils.raise_with_cause(exc_cls, message, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/oslo_utils/excutils.py", line 143, in raise_with_cause
    six.raise_from(exc_cls(message, *args, **kwargs), kwargs.get('cause'))
  File "/usr/lib/python2.7/site-packages/six.py", line 718, in raise_from
    raise value
ToozError: (0, '')

I looked around the source code and I suspect that this is caused by a leaked mysql cursor. Tooz creates cursors using `with self._conn as cur:`.
However, if you look at the source code of PyMySQL you will see that the connection doesn't close the cursor:

https://github.com/PyMySQL/PyMySQL/blob/master/pymysql/connections.py#L499-L508

The proper way of using cursors is exemplified in the PyMySQL examples:

with connection.cursor() as cursor:
    # do stuff

The fix would be to replace `with self._conn as cur:` with
`with self._conn.cursor() as cur:` in the mysql driver.

Tags: mysql
Alexandru Sorodoc (bno1)
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.