Handle leak in pyzmq?

Hi, nice people StackOverflow.

I use pyzmq and I have several lengthy processes, which led to the discovery that socket descriptors remain open. I narrowed the violation code to the following:

import zmq uri = 'tcp://127.0.0.1' sock_type = zmq.REQ linger = 250 # Observe output of lsof -p <pid> here and see no socket handles ctx = zmq.Context.instance() sock = ctx.socket(sock_type) sock.setsockopt(zmq.LINGER, linger) port = sock.bind_to_random_port(uri) # Observe output of lsof -p <pid> here and see many socket handles sock.close() # lsof -p <pid> still showing many socket handles ctx.destroy() # Makes no difference 

Pyzmq version - pyzmq-13.1.0

Either there is an error in pyzmq, or I'm doing something wrong. I hope you help me.

Thanks!

+6
source share
1 answer

After chatting with pieterh and minrk on #zeromq we found the reason.

ctx.destroy() in 13.1.0 has an indented error, so it only calls Context.term() if there is an open socket.

ctx.term() : Call ctx.term() instead and make sure all your sockets are closed before you do this.

+5
source

Source: https://habr.com/ru/post/958425/


All Articles