Version: 3.0beta1 (using KDE 4.0.0) Installed from: Gentoo Packages Compiler: gcc (GCC) 4.2.2 (Gentoo 4.2.2 p1.0) OS: Linux After a few hours of running ktorrent starts stopping torrents with "Too many open files". I have 13 seedings and 1 download active (about half of them with more then one file). When torrents are beign stopped a lot of sockets in CLOSE_WAIT state are still opened as this command shows: $ lsof -n -c ktorrent | grep "CLOSE_WAIT" | wc -l 624 In normal cases you should never keep a file descriptor open to a scoket in CLOSE_WAIT.
*** Bug 156331 has been marked as a duplicate of this bug. ***
SVN commit 764849 by guisson: Fix problem with connections staying in close_wait state BUG: 156163 M +4 -0 socket.cpp WebSVN link: http://websvn.kde.org/?view=rev&revision=764849
This is still a problem in ktorrent 3.0rc1
I'm not seeing it happening, and I'm absolutely sure then when you stop a torrent, all it's sockets are closed.
No they are not... I have just confirmed that after stopping all torrents ktorrent still have 369 fd's open to sockets in CLOSE_WAIT and 55 to sockets in ESTABLISHED.
This only hapens with local connections, remote connections are close properly. So you will not see this if you are behind a firewall. This is properly unrelated but ktorrent dosn't seem to use SO_REUSEADDR for listening connection, if I close ktorrent and start it again it fails to bind to the listening port and a "address already in use" error is written to the log.
Sorry, my mistake... it only hapens with remote connections, not with local connections. -- All sockets in CLOSE_WAIT are bound to ktorrents listening port.
I found it!! in bt::Server::newConnection(int) (server.cpp line 116) you call the mse::StreamSocket(int) constructor with the fd as only argument, however mse::StreamSocket(int) expect ip-version as only argument not a fd. The fd is after that lost and left open, authentication with that host fails as the socket is not connected. I have for now work around this by applaing this patch, it works for me as I don't use IPv6. You probebly should check the ip-version of the listening socket and use that instead: ---- diff -Naur ktorrent-3.0rc1/libbtcore/torrent/server.cpp ktorrent-3.0rc1.patched/libbtcore/torrent/server.cpp --- ktorrent-3.0rc1/libbtcore/torrent/server.cpp 2008-01-27 12:56:51.000000000 +0100 +++ ktorrent-3.0rc1.patched/libbtcore/torrent/server.cpp 2008-01-27 21:32:30.000000000 +0100 @@ -113,7 +113,7 @@ void Server::newConnection(int socket) { - mse::StreamSocket* s = new mse::StreamSocket(socket); + mse::StreamSocket* s = new mse::StreamSocket(socket, 4); if (peer_managers.count() == 0) { s->close();
SVN commit 767757 by guisson: Fix socket descriptor leak, big thanks to Richard Narstrom for finding the problem and the solution BUG: 156163 M +1 -0 ktorrent/main.cpp M +1 -1 libbtcore/torrent/server.cpp WebSVN link: http://websvn.kde.org/?view=rev&revision=767757