[Sqlalchemy-tickets] Issue #3803: DBAPI connections go invalid on KeyboardInterrupt, GreenletExit e
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2016-09-21 18:24:18
|
New issue 3803: DBAPI connections go invalid on KeyboardInterrupt, GreenletExit e.g BaseException but not Exception, simple invalidate() fixes. https://bitbucket.org/zzzeek/sqlalchemy/issues/3803/dbapi-connections-go-invalid-on Michael Bayer: case test3.py and test5.py illustrate pymysql connections being corrupted both by GreenletExit and KeyboardInterrupt. The program loop has many issues with "commands out of sync" for various reasons, but at the very least because when the error occurs, our context managers as well as pool logic wants to do a rollback(), such as Transaction.__exit__, which is already called for all BaseException subclasses, not just Exception, and this blows up because the connection is already corrupted; this occurs even if we use NullPool because we are still in the handling of the context. Similar tests against pymysql alone (test2.py, test4.py) illustrate that largely the same kind of connection corruption can be shown against C-based mysqlclient with the KeyboardInterrupt example, so this is not just a pure Python greenlet thing. _handle_dbapi_error() already handles Exception, adding support for BaseException and special "connection only, don't invalidate the pool" logic as in attached patch allow test3 / test5 to be run with no errors at all except normal interception of the KeyboardInterrupt / GreenletExit. |