anacrolix / utp

Use anacrolix/go-libutp instead
https://github.com/anacrolix/go-libutp
Mozilla Public License 2.0
173 stars 35 forks source link

Dial leaks file descriptors #8

Closed whyrusleeping closed 8 years ago

whyrusleeping commented 8 years ago

calling Dial opens a new socket, then calls dial on that socket. closing the returned connection doesnt appear to close the opened socket, leading to a file descriptor leak.

anacrolix commented 8 years ago

Hm good catch, I never use that part of the code. The logic behind Socket has changed a lot since that function was first written. Now the underlying "real" file descriptor should not be closed until all the uTP connections hanging from it (utp.Conn) are also closed and finalized. It should be sufficient to close the Socket as soon as a Conn is created by dialing on it.

whyrusleeping commented 8 years ago

@anacrolix so even though we call Close on the socket, it wont actually close until the Conn gets closed?

anacrolix commented 8 years ago

That's how it currently works. Of course if you use Dial() or DialTimeout() without your own Socket, one is made for you, and it appears that is never closed. I'm constructing a test for it now.

anacrolix commented 8 years ago

Well that was a deep rabbit hole. Please let me know if the commits I made address your problem. In particular ca69c553ddfe8406a28819ec0cb1fc198ea14628 fixes this, and the others fix a bunch of related stuff.

whyrusleeping commented 8 years ago

Thank you so much! I should have that integrated into go-ipfs by the end of the day. I'll test it out and let you know