Edgewall Software

Ticket #4802: mysql_safe_close-r4937.diff

File mysql_safe_close-r4937.diff, 880 bytes (added by cboos, 5 years ago)

Do the ping before the rollback (as originally proposed in #3645) and don't attempt to close if we know the connection is already lost.

  • trac/db/mysql_backend.py

     
    161161                                  host=host, port=port, use_unicode=True) 
    162162            self._set_character_set(cnx, 'utf8') 
    163163        ConnectionWrapper.__init__(self, cnx) 
     164        self._is_closed = False 
    164165 
    165166    def cast(self, column, type): 
    166167        if type == 'int': 
     
    180181        return self.cnx.insert_id() 
    181182 
    182183    def rollback(self): 
    183         self.cnx.rollback() 
    184         self.cnx.ping() 
     184        if self.cnx.ping(): 
     185            self.cnx.rollback() 
     186        else: 
     187            self._is_closed = True 
     188 
     189    def close(self): 
     190        if not self._is_closed: 
     191            self.cnx.close() 
     192            self._is_closed = True