[Zope3-Users] MySQL connection timeout problem

Brian Sutherland jinty at web.de
Mon Sep 18 21:02:25 EDT 2006


On Tue, Sep 19, 2006 at 02:14:39AM +0200, Brian Sutherland wrote:
> On Mon, Sep 18, 2006 at 10:19:06AM -0700, Michael Bernstein wrote:
> > Well, the problem requires an eight-hour timeout in order to manifest,
> > so the only reason I am hitting it is because my prototype app is idle
> > overnight. Does that help you reproduce it?
> 
> Can you try this patch (barring typos;):

For the record, this patch doesn't work in an interesting way!

> Index: adapter.py
> ===================================================================
> --- adapter.py	(revision 70218)
> +++ adapter.py	(working copy)
> @@ -77,3 +77,25 @@
>          connection = ZopeDatabaseAdapter.__call__(self)
>          directlyProvides(connection, IMySQLZopeConnection)
>          return connection
> +
> +    def isConnected(self):
> +        """Check if we are connected to a database.
> +        
> +        Try to solve the dissapearing connection problem. For background, see
> +        http://mail.zope.org/pipermail/zope3-dev/2005-December/017052.html
> +        """
> +        try:
> +            self._v_connection.ping()
> +        except MySQLdb.OperationalError:
> +            # not connected or ping did not restore MySQL connection
> +            if self._v_connection is not None:
> +                try:
> +                    # this is a bare except because at this point
> +                    # we are just trying to be nice closing the connection.
> +                    # The situation is bad anyway.
> +                    self._v_connection.close()
> +                except:
> +                    pass
> +                self._v_connection = None
> +            return False
> +        return True

-- 
Brian Sutherland

Metropolis - "it's the first movie with a robot. And she's a woman.
              And she's EVIL!!"


More information about the Zope3-users mailing list