#781: SQLObject does not reconnect
----------------------------------------------------+-----------------------
 Reporter:  ghaering                                |        Owner:  anonymous
     Type:  defect                                  |       Status:  new      
 Priority:  normal                                  |    Milestone:           
Component:  SQLObject                               |      Version:  0.9a4    
 Severity:  critical                                |   Resolution:           
 Keywords:  sqlobject 'MySQL server has gone away'  |  
----------------------------------------------------+-----------------------
Changes (by nEO):

  * keywords:  => sqlobject 'MySQL server has gone away'

Comment:

 It's a realy annoying problem.

 from mysql 5.0.3 the reconnect flag default is 0.

 so, after mysql wait_timeout, the connection is lost.

 http://dev.mysql.com/doc/refman/5.0/en/upgrading-from-4-1.html

 If your app using tg.visit,tg.identity, and your app idle time > mysql
 connection wait_timeout (set in my.cnf wait_timeout), Then you will lost
 all mysqldb connections. and all identy required pages will return 500
 server error.

 It's fairly easy repeat this problem, just set mysql wait_timeout to 10
 and quickstart a new project with identity. Then you will catch it.

 The call trace looks like:

 {{{
 Exception in thread VisitManager:
 Traceback (most recent call last):
   File "/usr/lib64/python2.4/threading.py", line 442, in __bootstrap
     self.run()
   File "/usr/lib64/python2.4/site-packages/TurboGears-0.9a8-
 py2.4.egg/turbogears/visit/api.py", line 256, in run
     self.update_queued_visits(queue)
   File "/usr/lib64/python2.4/site-packages/TurboGears-0.9a8-
 py2.4.egg/turbogears/visit/sovisit.py", line 73, in update_queued_visits
     conn.query( conn.sqlrepr(u) )
   File "/usr/lib64/python2.4/site-packages/SQLObject-0.7.1dev_r1675-
 py2.4.egg/sqlobject/dbconnection.py", line 305, in query
     return self._runWithConnection(self._query, s)
   File "/usr/lib64/python2.4/site-packages/SQLObject-0.7.1dev_r1675-
 py2.4.egg/sqlobject/dbconnection.py", line 219, in _runWithConnection
     val = meth(conn, *args)
   File "/usr/lib64/python2.4/site-packages/SQLObject-0.7.1dev_r1675-
 py2.4.egg/sqlobject/dbconnection.py", line 302, in _query
     self._executeRetry(conn, conn.cursor(), s)
   File "/usr/lib64/python2.4/site-packages/SQLObject-0.7.1dev_r1675-
 py2.4.egg/sqlobject/mysql/mysqlconnection.py", line 60, in _executeRetry
     return cursor.execute(query)
   File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 137,
 in execute
     self.errorhandler(self, exc, value)
   File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line
 33, in defaulterrorhandler
     raise errorclass, errorvalue
 OperationalError: (2006, 'MySQL server has gone away')

 }}}


 So, I do a quick dirty hack on SQLObject to handle the mysql connection
 timeout and mysql database restart.

 I think the best solution is SQLObject do a connection check before  do
 raw sql query, and handle OperationalError exception, if MySQL server is
 gone away then try to reconnect.

 here is the sqlobject patch for who is borning with the same problem.

 ----


 {{{
 gentoo sqlobject # diff -Nura dbconnection.py.orig dbconnection.py
 --- dbconnection.py.orig        2006-07-26 23:21:23.000000000 +0800
 +++ dbconnection.py     2006-07-27 00:12:44.000000000 +0800
 @@ -214,11 +214,27 @@
          self._binaryType = type(self.module.Binary(''))

      def _runWithConnection(self, meth, *args):
 +        try:
 +            import _mysql_exceptions
 +        except ImportError:
 +            MySQLdbExcept = ImportError
 +        else:
 +            MySQLdbExcept = _mysql_exceptions.OperationalError
 +
          conn = self.getConnection()
          try:
              val = meth(conn, *args)
 -        finally:
 +        except MySQLdbExcept:
 +            #print "make reconnection"
              self.releaseConnection(conn)
 +            conn = self.makeConnection()
 +            self._connectionNumbers[id(conn)] = self._connectionCount
 +            self._connectionCount += 1
 +            try:
 +                val = meth(conn, *args)
 +            finally:
 +                self.releaseConnection(conn)
 +        #finally:
          return val

      def getConnection(self):

 }}}

-- 
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/781>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Tickets" group.
To post to this group, send email to turbogears-tickets@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-tickets
-~----------~----~----~----~------~----~------~--~---

Reply via email to