m2r icon indicating copy to clipboard operation
m2r copied to clipboard

Prevent race condition when finished working

Open paneq opened this issue 12 years ago • 2 comments

Use ZMQ3 disconnect / unbind API whenever possible to avoid situation like this in Python mongrel2 adapter:

def shutdown(self,timeout=None):
        """Shut down the connection.

        This indicates that no more requests should be received by the
        handler, but it is willing to process any that have already been
        transmitted.  Use it for graceful termination of handlers.

        After shutdown, you may only call recv() with timeout=0.

        For the standard PULL socket, a clean shutdown is not possible
        as zmq has no API for it.  What we do is quickly ready anything
        that's pending for delivery then close the socket.  This leaves
        a slight race condition that a request will be pushed to us and
        then lost.
        """
        msg = self._recv(timeout=0)
        while msg is not None:
            self.recv_buffer.append(msg)
            msg = self._recv(timeout=0)
        self.send_sock.close()
        super(Connection,self).shutdown(timeout)

paneq avatar Jul 29 '12 21:07 paneq

https://github.com/chuckremes/ffi-rzmq/issues/57

paneq avatar Jul 29 '12 21:07 paneq

This was fixed in ffi-rzmq and we can start working on it.

paneq avatar Aug 03 '12 07:08 paneq