pushyrpc / pushy

Easy-as RPC. Zero-server RPC for Python and Java.
http://github.com/pushyrpc/pushy
45 stars 18 forks source link

Pipes leaking on connection close() #48

Open jpenney opened 11 years ago

jpenney commented 11 years ago

I've encountered a situation where pushy is leaking an open file descriptor (shows up as pipe under lsof) when the connection is closed. I think I've tracked it down to connection.server.stderr. I'm seeing this on Linux, so I'm not sure it applies everywhere. This is the simplest example I could come up with to illustrate (relies on psutil).

import sys
import pushy
import psutil
import os

proc = psutil.Process(os.getpid())

before = proc.get_num_fds()
conn = pushy.connect('local:', python=sys.executable)
conn.close()
after = proc.get_num_fds()

print "open/close - handles leaked: %d" % (after - before)

before = proc.get_num_fds()
conn = pushy.connect('local:', python=sys.executable)
conn.server.stderr.close()
conn.close()
after = proc.get_num_fds()

print "open/close stderr/close - handles leaked: %d" % (after - before)

output:

open/close - handles leaked: 1
open/close stderr/close - handles leaked: 0
axw commented 11 years ago

Thanks for reporting the issue and the repro. I'm away for work at the moment, so won't get to this for a bit. If you end up with a fix before me, please do send through a pull request.