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

Jp Calderone exarkun at divmod.com
Thu Mar 17 23:01:20 MST 2005


On Thu, 17 Mar 2005 23:58:55 +0100, Andrea Arcangeli <andrea at cpushare.com> wrote:
>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!
> 

  Glad to offer it :)  I wonder why you didn't go with the apparently equivalent but similar version of clientConnectionFailed, though:

    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:
            if self.continueTrying:
                self.connector = connector
                self.retry()
            return
        # workaround for bug in 1.3.0 - end
        ReconnectingClientFactory.clientConnectionFailed(
            self, connector, reason)

  I guess I can see how defining a function for the logic further separates it from the rest of the code, but why define it inside the version test if suite? :)  Maybe that was just the most convenient place at the moment..  The main difference, though, is the total absense of the if guarding the call to self.retry().  It seems like you duplicated the 1.3 logic in the 1.3 work-around code.  Maybe I'm just misreading it, but it seems like you just want to omit that test and always retry().

  Jp




More information about the Twisted-Python mailing list