[Twisted-Python] SMTPConnectError as a side effect on connection lost

Adi Roiban adi at roiban.ro
Sat Nov 25 21:52:20 MST 2017


I hit a strange behavior in which the clone connection error from one
test is raised as the error for another test.

The tests are not written using trial, but I have thousands of other
tests and I have never seen this behaviour.

I tried to put a self-contained example at

https://gist.github.com/adiroiban/edc0776e3337d0bd3f093aa0f2819deb#file-test-py

you will need to run it in a virtulenv as it will pull quite a few of
dependencies.

I have traced the error to this code
https://github.com/twisted/twisted/blob/03dcdfb5933c4f83ce6aad3f4bdf080cda65584c/src/twisted/mail/smtp.py#L1943

            if err.check(error.ConnectionDone):
                err.value = smtp.SMTPConnectError(
                    -1, "Unable to connect to server.")
            self.result.errback(err.value)

It looks to me like the initial failure (err) is hijacked here and its
errors will never be cleared.

If I am doing something like

            if err.check(error.ConnectionDone):
                value = smtp.SMTPConnectError(
                    -1, "Unable to connect to server.")
            else:
                value = err.value
            err.cleanFailure()
            self.result.errback(value)

then the test will pass.
But I still don't understand how the error from one client request is
passed to another client request when they are using different
servers.

Do you see anything suspicious with this code?

Thanks!
-- 
Adi Roiban



More information about the Twisted-Python mailing list