The documentation implies that the Deferred
at request.notifyFinish()
should be notified if the connection drops for any reason. I loaded similar code below:
from twisted.web.resource import Resource
from twisted.web.server import NOT_DONE_YET
from twisted.internet import reactor
from twisted.logger import Logger
log = Logger()
class DelayedResource(Resource):
isLeaf = 1
def _delayedRender(self, request):
log.info("Rendered!")
request.write("<html><body>Sorry to keep you waiting.</body></html>")
request.finish()
def _responseFailed(self, err, call):
call.cancel()
log.info("No. Wait. Stop")
def render_GET(self, request):
log.info("Lets try this!")
call = reactor.callLater(5, self._delayedRender, request)
request.notifyFinish().addErrback(self._responseFailed, call)
return NOT_DONE_YET
If I cancel the connection from the client, _responseFailed
does not get called. The log statement "No. Wait. Stop" is never printed and the "Rendered!" statement is printed.
This is important, because in my real use case the I am allocating resources that need to be deallocated if the connection drops. After upgrading to twisted 17.1.0, these stopped getting cleaned up.
Am I doing this wrong? Or is this a bug in twisted?