[zeromq-dev] XREQ+XREP losing messages when HWM is hit

Martin Lucina mato at kotelna.sk
Wed Jul 28 16:19:05 CEST 2010


Hi,

I've found what looks like a bug with the current git master.

The expected behaviour when HWM is hit would be for send() on a XREQ socket
to block until there is space in the underlying pipe. Instead, send()
appears to succeed (I can send any amount of requests) and the XREP end
only gets one.

The attached Python test programs are somewhat artificial, but demonstrate
the problem. They work fine with HWM not set, and should work just as well
with HWM=1 on the XREQ side.

--- XREQ side
import zmq

def main():
    ctx = zmq.Context(1)
    xreq = ctx.socket(zmq.XREQ)
    xreq.setsockopt(zmq.HWM, 1)
    xreq.connect("tcp://localhost:5000")
    for request_id in xrange(1,11):
        print "[XREQ] Sending request ", request_id
        xreq.send_multipart(['', str(request_id)])
        print "[XREQ] Sent request ", request_id

    received = 0
    while True:
        parts = xreq.recv_multipart()
        print "[XREQ] Received reply ", parts[1]
        received += 1
        if received == 10:
            break

if __name__ == "__main__":
    main ()
---

--- XREP side
import zmq

def main():
    ctx = zmq.Context(1)
    xrep = ctx.socket(zmq.XREP)
    xrep.bind("tcp://*:5000")
    while True:
        parts = xrep.recv_multipart()
        print "[XREP] Received request ", parts[2]
        xrep.send_multipart(parts)
        print "[XREP] Sent request ", parts[2]

if __name__ == "__main__":
    main ()
---

Either HWM with XREQ doesn't behave as I think it should, or this is a bug.

-mato



More information about the zeromq-dev mailing list