[ZODB-Dev] [ZEO] infinite loop during connection

Dieter Maurer dieter at handshake.de
Wed Dec 15 16:40:16 EST 2004


In our ZODB 3.2 version, we occasionally (about 1 in 1000)
observe an infinite loop in the ZEO client during connection
with the ZEO server.

The infinite loop happens in "ZEO.ServerStub.ServerStub.__init__"
in the loop:

        # Wait until we know what version the other side is using.
        while rpc.peer_protocol_version is None:
            rpc.pending()

In our case, the connection ("rpc") is in synchronous mode
such that "rpc.pending()" checks whether there is something to
read (and reads it in this case).

Apparently, the message with the server protocol version
is somehow lost. I do not understand how this may happen.


Nevertheless, the code (as it is now) is a bit stupid.
I cannot see a reason why "rpc.pending()" is not called with
a non-zero timeout value (this would allow for passive waiting
rather than busy waiting).

Calling "pending" with a timeout reduces the effects of the infinite loop
(creating a significant continuous load on the host) only for
synchronous mode. Therefore, I also added an explicit timeout.
Surpassing this timeout results in an exception.
My code now looks like:

        # Wait until we know what version the other side is using.
        st = time()
        while rpc.peer_protocol_version is None:
            if time() - st > ZEO_MAX_RESPONSE_TIME:
                # the server took too long to report its version
                rpc.close()
                raise EnvironmentError("ZEO server's initial response exceeded %ss" % ZEO_MAX_RESPONSE_TIME)
            rpc.pending(30)
        if rpc.peer_protocol_version == 'Z200':


-- 
Dieter


More information about the ZODB-Dev mailing list