When I send a data from a socket and then immediately close it (without changing the default settings), small data sizes are sent successfully but large ones (> 2MB) are not.
Here is how I set up the receiver (blocking on the recv() at the end):
In [1]: import zmq
In [2]: ctx = zmq.Context()
In [3]: socket = ctx.socket(zmq.PULL)
In [4]: socket.connect("ipc://@foo")
In [5]: msg = socket.recv()
And then the sender:
In [1]: import zmq
In [2]: ctx = zmq.Context()
In [3]: socket = ctx.socket(zmq.PUSH)
In [4]: socket.bind("ipc://@foo")
In [5]: arr = bytearray([1]*100)
In [6]: len(arr)
Out[6]: 100
In [7]: socket.send(arr); socket.close()
The receiver gets the data just fine:
In [5]: msg = socket.recv()
In [6]: len(msg)
Out[6]: 100
If however I use a larger message, say arr = bytearray([1]*int(2e6))
, then the receiver keeps blocking, waiting for data.
Changing the LINGER settings don't seem to make any difference (and I believe default to infinite wait anyway).
Adding a sleep(1) between sending and closing on the sender like
socket.send(arr); time.sleep(1); socket.close()
solves the problem: the receiver gets the data correctly.
Why is this not working without the sleep if LINGER defaults to -1? What is the correct way to send and then immediately close a socket when dealing with larger amounts of data?