[Twisted-Python] SSL4ClientEndpoint not updating the transport's connected flag on connection lost

Glyph Lefkowitz glyph at twistedmatrix.com
Sat Aug 20 01:37:59 MDT 2016


> On Aug 11, 2016, at 06:59, Adi Roiban <adi at roiban.ro> wrote:
> 
> Hi,
> 
> I have observed that when a SSL4ClientEndpoint was used, the
> protocol's transport `connected` attribute is not updated by the
> wrapper when the connection is lost.

Hey Adi,

I took a look through the code, and I think it's a lot simpler than you realize :-).

> My current finding is that the reactor will call connection lost on
> t.i.abstract.FileDescriptor.connectionLost and not on
> t.protocols.policies.ProtocolWrapper

This is definitely not true, or dropping the connection just wouldn't work at all, and you wouldn't get connectionLost on your protocol.  The call path is FileDescriptor.connectionLost -> endpoint wrapper protocol.connectionLost -> *TLS wrapper protocol.connectionLost* -> your protocol connectionLost.

The bold-faced protocol is the interesting one, because that is the 'transport' object that your protocol sees.  Here's that object's connectionLost method:

https://github.com/twisted/twisted/blob/6022f65903eda2f8df74b2d284b8ef359df24904/src/twisted/protocols/tls.py#L488 <https://github.com/twisted/twisted/blob/6022f65903eda2f8df74b2d284b8ef359df24904/src/twisted/protocols/tls.py#L488>

As you can see, neither it, nor the superclass that it upcalls to <https://github.com/twisted/twisted/blob/6022f65903eda2f8df74b2d284b8ef359df24904/src/twisted/protocols/policies.py#L123 <https://github.com/twisted/twisted/blob/6022f65903eda2f8df74b2d284b8ef359df24904/src/twisted/protocols/policies.py#L123>> sets the "connected" attribute.  So the method is totally called, it just doesn't do what you expect.

> so it seems that when SSL is used the wrapped protocol is registered
> instead of the wrapping protocol.

I'm not sure what you mean here.

> I am doing something wrong here?

> Is this the expected behavior or this is a bug?

Probably both, kinda?  This attribute is undocumented; probably an old implementation accident.  Technically it's public, but you probably shouldn't be depending on it.  However, it's silly that this is inconsistent between TLS transports and raw TCP transports, so fixing up ProtocolWrapper.connectionLost to set 'connected' to False is probably not a bad change.

-glyph

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20160820/af59d3ce/attachment-0002.html>


More information about the Twisted-Python mailing list