[Twisted-Python] how to "close" a TLS connection?

Jean-Paul Calderone exarkun at divmod.com
Wed May 17 14:03:17 MDT 2006


On Wed, 17 May 2006 17:00:29 -0200, Manlio Perillo <manlio_perillo at libero.it> wrote:
>Hi.
>
>I'm doing some unit test with TLS but I got:
>
>twisted.trial.util.DirtyReactorError: THIS WILL BECOME AN ERROR SOON!
>reactor left in unclean state, the following Selectables were left over:
> <<class 'twisted.internet.tcp.TLSConnection'> to ('localhost', 5432) at
>f0e590>
>
>
>All is ok if I do not use TLS (I simply close the connection).
>
>What's the problem?
>

TLS close adds a layer of back and forth traffic on top of the existing TCP close handshake.  Your test probably assumes that loseConnection() will drop the connection within a certain number of round-trips, but the added TLS negotiation pushes the actual shutdown over that threshhold, so the connection is still around when trial gets around to looking for such things.

You should add a Deferred which is fired by the protocol's connectionLost method or the factory's clientConnectionLost method, and make sure your test doesn't end until that Deferred fires.

Jean-Paul




More information about the Twisted-Python mailing list