Opened 3 years ago

Last modified 5 weeks ago

#4964 defect new

adbapi.Transaction.reopen doesn't reconnect when mysql backend closes a connection

Reported by: jsw Owned by:
Priority: high Milestone:
Component: core Keywords: connection, adbapi, transaction, error
Cc: writetojay@…, spam+twistedmatrix.com@… Branch:
Author: Launchpad Bug:

Description

Hi twisteds,

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.

Attachments (1)

mysql_testing.py (784 bytes) - added by jsw 3 years ago.
example which triggers the problem

Download all attachments as: .zip

Change History (6)

Changed 3 years ago by jsw

example which triggers the problem

comment:1 Changed 3 years ago by jsw

  • Cc writetojay@… added
  • Type changed from enhancement to defect

comment:2 Changed 3 years ago by jsw

  • Priority changed from normal to high

comment:4 Changed 6 months ago by pesach

  • Keywords connection adbapi transaction error added

The link added by amberite above, referencing a possible solution, appears to be dead. An archived version of the solution can currently be found here:

https://web.archive.org/web/20131007031559/http://www.gelens.org/2009/09/13/twisted-connectionpool-revisited/

comment:5 Changed 5 weeks ago by posita

  • Cc spam+twistedmatrix.com@… added
Note: See TracTickets for help on using tickets.