Ticket #4719 defect closed fixed
connectionLost never reached after calling loseConnection: stuck in CLOSE_WAIT forever
Description
A is a twisted.internet.tcp.Connection transport connecting a socket to a protocol. A has a producer C. A is a consumer of B. More than 64KB are written to A. At some point B gives up and tells A to stopProducing (loseConnection). A.loseConnection stops the reactor from reading OneA and starts it writing. A.doWrite happens:
* it finds the send buffer empty * it finds a registered producer (C) and resumes it
C never produces any more bytes. After some time (reactor.callLater 0 is not enough), C unregisters itself from A. A takes note that it has no more producer, but does nothing about it. A's protocol's connectionLost is never called even if its peer shuts down the connection. A's socket is stuck in CLOSE_WAIT state forever with 1 byte in the Recv-Q and 0 bytes in Send-Q.
Exarkun said that the bug is likely that FileDescriptor.unregisterProducer doesn't do anything special when disconnecting=True.
Please see the attached file that demonstrates the problem.
Please also see: http://twistedmatrix.com/pipermail/twisted-python/2010-October/023088.html

