[Twisted-Python] socket is not closed when connection failed
Hi everyone, I found that if a TCP connection is failed, e.g. UserTimeout or No route to host, connection refused, etc, i.e. when factory.ConnectionFailed is called, the socket is not properly cleaned up. i.e. socket.close() wasn't called. In this case, when I try to connect to many unreachable hosts, my file descriptor will finally be gone. Could someone confirm me on this? Thanks. I'm using twisted 1.3.0rc1 Yun
Here is a quick patch to twisted/internet/tcp.py that seems to fix it. internet# diff tcp.py tcp_old.py 360,366d359 < # patched by maoy for cleaning resources when connectionFailed######## < if hasattr(self, "socket"): < if self.socket: self.socket.close() < del self.socket < if hasattr(self, "fileno"): < del self.fileno < #end patch######### Yun On Wed, 16 Feb 2005, Yun Mao wrote:
Hi everyone,
I found that if a TCP connection is failed, e.g. UserTimeout or No route to host, connection refused, etc, i.e. when factory.ConnectionFailed is called, the socket is not properly cleaned up. i.e. socket.close() wasn't called. In this case, when I try to connect to many unreachable hosts, my file descriptor will finally be gone.
Could someone confirm me on this? Thanks. I'm using twisted 1.3.0rc1
Yun
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Itamar Shtull-Trauring wrote:
On Wed, 2005-02-16 at 16:29 -0500, Yun Mao wrote:
Here is a quick patch to twisted/internet/tcp.py that seems to fix it.
Could you add this to twistedmatrix.com/bugs/?
Hi Itamar, Mary How serious is this bug? I'm particularly concern about twisted.web.server. Liming
On Thu, 2005-02-17 at 21:00 +0800, Tsai Li Ming wrote:
How serious is this bug? I'm particularly concern about twisted.web.server.
1. Servers don't open connections, so it's not relevant there. 2. It probably does not cause fd leaks, since python's gc will likely do that. close()ing explicitly is better, obviously.
2. It probably does not cause fd leaks, since python's gc will likely do that. close()ing explicitly is better, obviously.
I ran out of fds once. I guess Python gc doesn't get called very often because a socket object doesn't cost too much memory. Y
On Thu, 17 Feb 2005 10:40:56 -0500, Itamar Shtull-Trauring <itamar@itamarst.org> wrote:
On Thu, 2005-02-17 at 21:00 +0800, Tsai Li Ming wrote:
How serious is this bug? I'm particularly concern about twisted.web.server.
1. Servers don't open connections, so it's not relevant there.
2. It probably does not cause fd leaks, since python's gc will likely do that. close()ing explicitly is better, obviously.
As a rough figure, with a max file descriptors limit of 1024, on Python 2.3.5, this tends not to be a problem with connection rates below 100 failed connections per second. The file descriptors are eventually closed by the Python GC, it just takes a little while since the sockets are part of cyclic garbage. Jp
Jp Calderone wrote:
On Thu, 17 Feb 2005 10:40:56 -0500, Itamar Shtull-Trauring <itamar@itamarst.org> wrote:
On Thu, 2005-02-17 at 21:00 +0800, Tsai Li Ming wrote:
How serious is this bug? I'm particularly concern about twisted.web.server.
1. Servers don't open connections, so it's not relevant there.
2. It probably does not cause fd leaks, since python's gc will likely do that. close()ing explicitly is better, obviously.
As a rough figure, with a max file descriptors limit of 1024, on Python 2.3.5, this tends not to be a problem with connection rates below 100 failed connections per second. The file descriptors are eventually closed by the Python GC, it just takes a little while since the sockets are part of cyclic garbage.
Jp
I see what you mean. Upon looking fuerther at the tcp.py, the code section is for tcp clients, not "TCP Server Port". Thanks, Liming
participants (4)
-
Itamar Shtull-Trauring
-
Jp Calderone
-
Tsai Li Ming
-
Yun Mao