#4964 defect new
adbapi.Transaction.reopen doesn't reconnect when mysql backend closes a connection
|Reported by:||Jay Sweeney||Owned by:|
|Component:||core||Keywords:||connection, adbapi, transaction, error|
|Cc:||Jay Sweeney, posita||Branch:|
Not entirely sure if this is a bug with mysql drivers/backend or with adbapi, but, the behaviour I'm seeing is that if a mysql decides to close a client connection, then a connection in adbapi is not reconnecting even if the ConnectionPool has self.reconnect=True.
An easy way to test this is to set mysql's 'wait_timeout' setting to something very low and then create an adbapi pool and make queries separated by larger time intervals than the timeout setting. The result is that connections in the pool are disconnected by mysql and they never reconnect. I've tried this using both the MySQLdb and pymysql drivers.
The problem is, Line 106 of trunk in adbapi.Transaction.reopen:
self._cursor = self._connection.cursor()
is treated as though it would throw an exception if the underlying connection to the mysql server were closed. This is not the case. No exception is thrown by the .cursor() call on a dead connection. If you were to run, say, self._pool.good_sql, then the exception would indeed be thrown, and the connection would be reconnected as expected.