Skip to content

Commit

Permalink
Abort timed out connections with abortConnection()
Browse files Browse the repository at this point in the history
Timed out connections are not always killed with transport.loseConnection().
Call transport.abortConnection() instead.

http://twistedmatrix.com/documents/12.2.0/core/howto/servers.html

This fixes the memory leaking issues.
  • Loading branch information
tadasvaranavicius committed Feb 2, 2013
1 parent 19bf4ea commit 19f0e6e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions p2pool/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ def connectionMade(self):
def _connect_timeout(self):
self.timeout_delayed = None
print 'Handshake timed out, disconnecting from %s:%i' % self.addr
self.transport.loseConnection()
if self.transport.abortConnection is not None:
# Available since Twisted 11.1
self.transport.abortConnection()
else:
# This doesn't always close timed out connections!
self.transport.loseConnection()

def packetReceived(self, command, payload2):
try:
Expand All @@ -101,7 +106,12 @@ def badPeerHappened(self):
def _timeout(self):
self.timeout_delayed = None
print 'Connection timed out, disconnecting from %s:%i' % self.addr
self.transport.loseConnection()
if self.transport.abortConnection is not None:
# Available since Twisted 11.1
self.transport.abortConnection()
else:
# This doesn't always close timed out connections!
self.transport.loseConnection()

message_version = pack.ComposedType([
('version', pack.IntType(32)),
Expand Down

0 comments on commit 19f0e6e

Please sign in to comment.