Check for None-reply in _do_die

Fixes #2304

In some cases, the finished handler fired before the error handler, e.g.
when downloading a 500 error page that is sent as attachment:

    HTTP/1.1 500 Internal Server Error
    Content-Type: application/octet-stream
    Content-Disposition: inline; filename="attachment.jpg"

here we downloaded 0 bytes, fired the finished handler and after that
fired the error handler because of the 500 - but the finished handler
had already set our reply to None (and displayed the error message).
This commit is contained in:
Daniel Schadt 2017-03-21 18:54:21 +01:00
parent 081abde9cd
commit ebc70f66e5

View File

@ -110,6 +110,9 @@ class DownloadItem(downloads.AbstractDownloadItem):
def _do_die(self):
"""Abort the download and emit an error."""
self._read_timer.stop()
if self._reply is None:
log.downloads.debug("Reply gone while dying")
return
self._reply.downloadProgress.disconnect()
self._reply.finished.disconnect()
self._reply.error.disconnect()