Ticket #4710 defect closed fixed
TCP4ClientEndpoint.connect's deferred cannot be cancelled successfully
|Reported by:||marienz||Owned by:||glyph|
If you try to cancel the deferred returned from TCP4ClientEndpoint before it has connected the following happens:
- the _canceller function in t.i.endpoints calls connector.stopConnecting()
- this ends up calling connector.connectionFailed()
- connectionFailed calls factory.clientConnectionFailed
- factory is the endpoints._WrappingFactory, whose clientConnectionFailed errbacks its deferred (the same deferred we are cancelling)
- the canceller then tries to errback its deferred with a ConnectingCancelledError, which triggers AlreadyCalledError
test_endpoints misses this because the MemoryReactor's _FakeConnector's stopConnecting does not do anything (so it does not hit the factory's clientConnectionFailed).
Attached is a pretty terrible testcase demonstrating this, which fails for me with an AlreadyCalledError on twisted 10.1.0 and trunk.