[Twisted-Python] help with ssl timeout and not reconnecting client factory

Andrea Arcangeli andrea at cpushare.com
Thu Mar 17 15:58:55 MST 2005


On Thu, Mar 17, 2005 at 11:51:04AM -0500, Itamar Shtull-Trauring wrote:
> There was a bug in 1.3 in ReconnectingClientFactory that caused it to
> not reconnect on TimeoutErrors. It's fixed in 2.0.

Ok. This should workaround the bug in my app:

Index: cpushare/proto.py
===================================================================
RCS file: /home/andrea/crypto/cvs/cpushare/client/cpushare/cpushare/proto.py,v
retrieving revision 1.29
diff -u -p -r1.29 proto.py
--- cpushare/proto.py	13 Mar 2005 23:18:24 -0000	1.29
+++ cpushare/proto.py	17 Mar 2005 22:56:20 -0000
@@ -148,8 +148,24 @@ class cpushare_factory(ReconnectingClien
 		protocol.factory = self
 		return protocol
 
+	def clientConnectionLost(self, connector, reason):
+		print 'Lost connection. Reason:', reason
+		ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
+
 	def clientConnectionFailed(self, connector, reason):
 		print 'Connection failed. Reason:', reason
+		# workaround for bug in 1.3.0 - start
+		from twisted.copyright import version
+		if '1.3.0' in version:
+			def workaround_clientConnectionFailed(connector, reason):
+				if self.continueTrying:
+					self.connector = connector
+					from twisted.internet import interfaces, error, defer
+					if not reason.check(error.UserError) or reason.check(defer.TimeoutError):
+						self.retry()
+			workaround_clientConnectionFailed(connector, reason)
+			return
+		# workaround for bug in 1.3.0 - end
 		ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
 
 	def connectionMade(self):


Thanks Itamar and Jp for the help!




More information about the Twisted-Python mailing list