• Tim Peters's avatar
    Merge rev 29052 from 3.3 branch. · 3ebdc9a2
    Tim Peters authored
    Port from ZODB 3.2.
    
    Fixed several thread and asyncore races in ZEO's connection dance.
    
    ZEO/tests/ConnectionTests.py
        The pollUp() and pollDown() methods were pure busy loops whenever
        the asyncore socket map was empty, and at least on some flavors of
        Linux that starved the other thread(s) trying to do real work.
        This grossly increased the time needed to run tests using these, and
        sometimes caused bogus "timed out" test failures.
    
    ZEO/zrpc/client.py
    ZEO/zrpc/connection.py
        Renamed class ManagedConnection to ManagedClientConnection, for clarity.
    
        Moved the comment block about protocol negotiation from the guts of
        ManagedClientConnection to before the Connection base class -- the
        Connection constructor can't be understood without this context.  Added
        more words about the delicate protocol negotiation dance.
    
        Connection class:  made this an abstract base clase.  Derived classes
        _must_ implement the handshake() method.  There was really nothing in
        common between server and client wrt what handshake() needs to do, and
        it was confusing for one of them to use the base class handshake() while
        the other replaced handshake() completely.
    
        Connection.__init__:  It isn't safe to register with asyncore's socket
        map before special-casing for the first (protocol handshake) message is
        set up.  Repaired that.  Also removed the pointless "optionalness" of
        the optional arguments.
    
        ManagedClientConnection.__init__:  Added machinery to set up correct
        (thread-safe) message queueing.  There was an unrepairable hole before,
        in the transition between "I'm queueing msgs waiting for the server
        handshake" and "I'm done queueing messages":  it was impossible to know
        whether any calls to the client's "queue a message" method were in
        progress (in other threads), so impossible to make the transition safely
        in all cases.  The client had to grow its own message_output() method,
        with a mutex protecting the transition from thread races.
    
        Changed zrpc-conn log messages to include "(S)" for server-side or
        "(C)" for client-side.  This is especially helpful for figuring out
        logs produced while running the test suite (the server and client
        log messages end up in the same file then).
    3ebdc9a2
connection.py 29 KB