# Buggy code
def stop(self):
    """Stop creating the stream. Create the terminating zero-length blob."""
    log.debug("stop has been called for StreamCreator")
    self.stopped = True
    if self.current_blob is not None:
        self._close_current_blob()
    self._finalize()
    dl = defer.DeferredList(self.finished_deferreds)
    dl.addCallback(lambda _: self._finished())
    dl.addErrback(self._error)
    return dl


# Traceback (KeyError)
2017-09-19 09:47:51,891 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://battlefront-ii-storytrailer (5c3d3c) is finished
2017-09-19 09:47:51,904 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://hitmans-bodyguard-trailer (3303b0) is running
2017-09-19 09:47:51,914 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://thelovewitch-trailer (59edac) is finished
2017-09-19 09:47:51,964 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://bellflower-trailer (618fbb) is finished
2017-09-19 09:47:51,986 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://itsadisaster-threesome (395066) is finished
2017-09-19 09:47:51,987 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://jinglebellrocks-trailer (224aa1) is finished
2017-09-19 09:47:52,009 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://pub (57fdb5) is finished
2017-09-19 09:47:52,025 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://lbryscrreen1 (2dab0b) is finished
2017-09-19 09:47:52,072 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://lbryscrreen1 (2dab0b) is finished
2017-09-19 09:47:52,082 INFO     lbrynet.core.client.ConnectionManager:42: Connection Manager The Hitman’s Bodyguard - Redband Trailer (2017).mp4 initialized
2017-09-19 09:47:52,084 INFO     lbrynet.core.client.ConnectionManager:42: Connection Manager 1 - 'Fear the Boom and Bust' - Keynes vs. Hayek Rap Battle.mp4 initialized
2017-09-19 09:47:52,099 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://kedi-trailer (5731e9) is stopped
2017-09-19 09:47:52,114 INFO     lbrynet.file_manager.EncryptedFileDownloader:32: lbry://kedi-trailer (5731e9) is stopped
2017-09-19 09:47:52,142 CRITICAL twisted:154: Unhandled error in Deferred:
2017-09-19 09:47:52,144 CRITICAL twisted:154:
Traceback (most recent call last):
File "site-packages\twisted\internet\defer.py", line 1299, in _inlineCallbacks
File "site-packages\lbrynet\core\client\BlobRequester.py", line 70, in get_new_peers_for_head_blob
File "site-packages\lbrynet\core\client\DownloadManager.py", line 103, in get_head_blob_hash
KeyError: 0
2017-09-19 09:47:52,150 CRITICAL twisted:154: Unhandled error in Deferred:
2017-09-19 09:47:52,150 CRITICAL twisted:154:
Traceback (most recent call last):
File "site-packages\twisted\internet\defer.py", line 1299, in _inlineCallbacks
File "site-packages\lbrynet\core\client\BlobRequester.py", line 70, in get_new_peers_for_head_blob
File "site-packages\lbrynet\core\client\DownloadManager.py", line 103, in get_head_blob_hash
KeyError: 0

# Fixed code
def stop(self):
    """Stop creating the stream. Create the terminating zero-length blob."""
    log.debug("stop has been called for StreamCreator")
    self.stopped = True
    if self.current_blob is not None:
        self._close_current_blob()
    self._finalize()
    dl = defer.DeferredList(self.finished_deferreds)
    dl.addCallback(lambda _: self._finished())
    return dl