Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak (and other problems) with send_string() and recv_string() #531

Closed
jwezel opened this issue Apr 18, 2014 · 3 comments · Fixed by #532
Closed

Memory leak (and other problems) with send_string() and recv_string() #531

jwezel opened this issue Apr 18, 2014 · 3 comments · Fixed by #532

Comments

@jwezel
Copy link

jwezel commented Apr 18, 2014

Both send_string() (alias send_unicode) and recv_string() (alias recv_unicode) leak memory. The following code reproduces the problem:

Server:

import zmq

cx = zmq.Context()
so = cx.socket(zmq.ROUTER)
so.bind('tcp://127.0.0.1:3333')
while True:
    p = so.recv()
    m = so.recv_unicode()

Client:

import zmq
import time

cx = zmq.Context()
so = cx.socket(zmq.DEALER)
so.connect('tcp://127.0.0.1:3333')
s = '**********************************************************'
for i in xrange(1000000):
    so.send_unicode(s)
    time.sleep(.001)
so.close()
cx.term()

Environment

  • Python: 2.7.5
  • pyzmq: 14.0.1
  • zmq: 4.0.4

Furthermore, when the output queue fills up in the client (when sending too fast), then the error message
pyzmq-gc connect failed: Socket operation on non-socket is displayed which is not very helpful.

@minrk
Copy link
Member

minrk commented Apr 18, 2014

Anything that affects send/recv_string must also affect send/recv, unless there is a leak in the Python unicode.encode/bytes.decode methods (unlikely).

There is a leak in zero-copy send/recv in 14.0 (#486), which is fixed in master (by #517), but should only come up when copy=False. I bring this up because your comment about pyzmq-gc suggest that you are using zero-copy, where there is a known leak (fixed in master), but your sample here does not.

Can you reproduce the leak in current master?

@jwezel
Copy link
Author

jwezel commented Apr 18, 2014

Nope, looks fine now. Thanks.

BTW, send_string/recv_string always do copy=False, shouldn't this be left to the caller of the method?

@minrk
Copy link
Member

minrk commented Apr 18, 2014

send_string does not set copy=False, but recv_string does. I'll fix that
now.​

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants