[Twisted-Python] Properly handling Connection Refused

Beau Hargis beau at subobscur.us
Wed Sep 5 15:37:16 EDT 2007


Well, it subclasses 'protocol.ClientFactory'. I did not try 'ReconnectingClientFactory' yet as I wanted a little bit more control of the reconnecting process at some point. In any case, these functions are defined in the class as such:

    def clientConnectionFailed(self, connector, reason):
        print 'Connection failed. Reason: ', reason
        reactor.callLater(random.randint(10,91), connector.connect)

    def clientConnectionLost(self, connector, reason):
        print 'Connection Lost. Reason: ', reason
        reactor.callLater(random.randint(10,91), connector.connect)

Works ok for every other problem except Connection Refused. When I first started testing reconnect, the seconds argument to callLater was constant like 3 or 4 seconds and it did the same thing.  Even immediate reconnection caused the same problem with Connection Refused: 111.

----- Original Message ----
From: Jean-Paul Calderone <exarkun at divmod.com>
To: Twisted general discussion <twisted-python at twistedmatrix.com>
Sent: Wednesday, September 5, 2007 12:29:15 PM
Subject: Re: [Twisted-Python] Properly handling Connection Refused

On Wed, 5 Sep 2007 12:24:35 -0700 (PDT), Beau Hargis <beau at subobscur.us> wrote:
>I have this application built in twisted that is pretty robust save for one thing. The server reconnects when it falters or fails for any reason EXCEPT a refused connection, which happens when connecting to services on the Windows servers we have where particular services have not yet been started, which is normal. Every other failure is handled gracefully, including the database disappearing suddenly. I print out the reason in the log and I get this error:
>
>[Uninitialized]  Reason:  [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionRefusedError'>: Connection was refused by other side: 111: Connection refused.
>[Uninitialized] ]
>[Uninitialized] Stopping factory <SomeFactory instance at 0x88b77ac>
>
>And the whole thing stops processing and does not restart the connection.

How did you implement reconnection?

Jean-Paul

_______________________________________________
Twisted-Python mailing list
Twisted-Python at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python







More information about the Twisted-Python mailing list