[Twisted-Python] startTLS errors not propagating to Factory

Richard van der Hoff richard at matrix.org
Fri Apr 9 17:07:08 MDT 2021


Hi folks,

I've been investigating 
https://github.com/matrix-org/synapse/issues/9566, which amounts to: 
"when there is a TLS error connecting to the SMTP server, the resultant 
exception is unreadable".

I think I've traced the problem to the fact that 
SMTPSenderFactory.clientConnectionFailed is being called with an 
unhelpful ConnectionAborted rather than anything more descriptive.

I've then reproduced that with a simpler test case: see 
https://gist.github.com/richvdh/909761ff5dab23f0873eeddd7936a740. As you 
can see, the output is: "Factory lost connection. Reason: Connection was 
aborted locally using ITCPTransport.abortConnection."

This seems to be thanks to TLSMemoryBIOProtocol.failVerification, which 
stashes the error and calls abortConnection(): 
https://github.com/twisted/twisted/blob/trunk/src/twisted/protocols/tls.py#L427.

At this point I'm struggling. Is the SMTP code holding the Factory 
wrong? Or is it reasonable to expect the verification error to propagate 
into clientConnectionFailed - in which case, how could this work?

Thanks for your thoughts!

Richard



More information about the Twisted-Python mailing list