handle_dbapi_exception is missed on _revalidate_connection
Issue #3266
resolved
this might be too risky for 0.9, here's a stack trace under 0.9.8 (the second one):
#!
(py27)vsergeev@vsergeev-pc:~/sandbox/nova$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from nova.db.sqlalchemy import api
>>> conn = api.get_engine().connect()
No handlers could be found for logger "oslo.db.sqlalchemy.session"
>>> conn.execute("select 1").scalar()
1L
>>> # stop mysql
...
>>> conn.execute("select 1").scalar()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 721, in execute
return self._execute_text(object, multiparams, params)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 870, in _execute_text
statement, parameters
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 958, in _execute_context
context)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1155, in _handle_dbapi_exception
if newraise:
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 951, in _execute_context
context)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 436, in do_execute
cursor.execute(statement, parameters)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
oslo.db.exception.DBConnectionError: (OperationalError) (2006, 'MySQL server has gone away') 'select 1' ()
>>> conn.execute("select 1").scalar()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 721, in execute
return self._execute_text(object, multiparams, params)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 870, in _execute_text
statement, parameters
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 893, in _execute_context
None, None)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1155, in _handle_dbapi_exception
if newraise:
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 236, in connection
return self._revalidate_connection()
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 244, in _revalidate_connection
self.__connection = self.engine.raw_connection()
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1848, in raw_connection
return self.pool.unique_connection()
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/pool.py", line 280, in unique_connection
return _ConnectionFairy._checkout(self)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/pool.py", line 644, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/pool.py", line 442, in checkout
dbapi_connection = rec.get_connection()
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/pool.py", line 506, in get_connection
self.connection = self.__connect()
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/pool.py", line 538, in __connect
connection = self.__pool._creator()
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 96, in connect
connection_invalidated=invalidated
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 90, in connect
return dialect.connect(*cargs, **cparams)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 377, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/home/vsergeev/sandbox/nova/.tox/py27/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
sqlalchemy.exc.OperationalError: (OperationalError) (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") None None
Comments (3)
-
reporter -
reporter - changed status to resolved
- The engine-level error handling and wrapping routines will now
take effect in all engine connection use cases, including
when user-custom connect routines are used via the
:paramref:
.create_engine.creator
parameter, as well as when the :class:.Connection
encounters a connection error on revalidation. fixes#3266
→ <<cset 41e7253dee16>>
-
reporter - keep working on fixing
#3266, more cases, more tests
→ <<cset 347db81aea9b>>
- keep working on fixing
- Log in to comment
alternatively, if we're 1.0'ing this, maybe we should look into linking _handle_dbapi_error right into strategies -> connect(), or into the pool somehow