# Buggy code
def on_blob(self, peer, blob):
    """
    Callback for when a MetadataBlob message comes in.

    :param peer: the peer that sent us the blob
    :param blob: payload raw data
    """

    try:
        with db_session:
            try:
                md_list = self.metadata_store.process_compressed_mdblob(blob.raw_blob)
            except RuntimeError:
                return
            except (TransactionIntegrityError, CacheIndexError) as err:
                self._logger.error(
                    "DB transaction error when tried to process payload: %s", str(err)
                )
                return
    # Unfortunately, we have to catch the exception twice, because Pony can raise them both on the exit from
    # db_session, and on calling the line of code
    except (TransactionIntegrityError, CacheIndexError) as err:
        self._logger.error(
            "DB transaction error when tried to process payload: %s", str(err)
        )
        return

    # Check if the guy who send us this metadata actually has an older version of this md than
    # we do, and queue to send it back.
    with db_session:
        reply_list = [
            md
            for md, result in md_list
            if (md and (md.metadata_type == CHANNEL_TORRENT))
            and (result == GOT_NEWER_VERSION)
        ]
        reply_blob = (
            entries_to_chunk(reply_list, maximum_payload_size)[0]
            if reply_list
            else None
        )
    if reply_blob:
        self.endpoint.send(
            peer.address,
            self.ezr_pack(self.NEWS_PUSH_MESSAGE, RawBlobPayload(reply_blob)),
        )


# Traceback (RuntimeError)
ERROR   1551843034.02    LibtorrentDownloadImpl:788  (LibtorrentDownloadImpl)  Resume data failed to save: <class 'Tribler.Core.exceptions.SaveResumeDataError'>: torrent has no metadata
Unhandled error in Deferred:

ERROR   1551843034.15            tribler_window:67   (root)  Traceback (most recent call last):
File "TriblerGUI\event_request_manager.py", line 135, in on_read_data
RuntimeError: [Failure instance: Traceback: <type 'exceptions.RuntimeError'>: LZ4F_decompress failed with code: ERROR_decompressionFailed
lib\site-packages\twisted\internet\base.py:1243:run
lib\site-packages\twisted\internet\base.py:1252:mainLoop
lib\site-packages\twisted\internet\base.py:878:runUntilCurrent
lib\site-packages\twisted\internet\task.py:239:__call__
--- <exception caught here> ---
lib\site-packages\twisted\internet\defer.py:150:maybeDeferred
Tribler\Core\Libtorrent\LibtorrentMgr.py:612:_task_process_alerts
Tribler\Core\Libtorrent\LibtorrentMgr.py:408:process_alert
Tribler\Core\Libtorrent\__init__.py:17:invoke_func
Tribler\Core\Libtorrent\LibtorrentDownloadImpl.py:488:process_alert
Tribler\Core\Libtorrent\__init__.py:17:invoke_func
Tribler\Core\Libtorrent\LibtorrentDownloadImpl.py:628:on_torrent_finished_alert
Tribler\Core\Modules\gigachannel_manager.py:185:<lambda>
Tribler\Core\Modules\gigachannel_manager.py:115:on_channel_download_finished
Tribler\Core\Modules\MetadataStore\store.py:182:process_channel_dir
<auto generated wrapper of process_mdblob_file() function>:2:process_mdblob_file
lib\site-packages\pony\orm\core.py:515:new_func
Tribler\Core\Modules\MetadataStore\store.py:202:process_mdblob_file
<auto generated wrapper of process_compressed_mdblob() function>:2:process_compressed_mdblob
lib\site-packages\pony\orm\core.py:515:new_func
Tribler\Core\Modules\MetadataStore\store.py:207:process_compressed_mdblob
]

INFO    1551843034.17                 community:506  (TrustChainTestnetCommunity)  Received crawl request from node 5e00a2d9 for range 383-383
INFO    1551843034.18                 community:539  (TrustChainTestnetCommunity)  Sent 2 blocks
INFO    1551843034.31            LaunchManyCore:690  (TriblerLaunchMany)  tlm: early_shutdown
INFO    1551843034.31                   Session:543  (Session)  Tribler shutdown state notification:Shutting down Credit Mining...
INFO    1551843034.31       CreditMiningManager:105  (CreditMiningManager)  Shutting down CreditMiningManager
INFO    1551843034.31                   Session:543  (Session)  Tribler shutdown state notification:Shutting down Torrent Checker...
INFO    1551843034.34                   Session:543  (Session)  Tribler shutdown state notification:Shutting down Gigachannel Manager...
INFO    1551843034.34                   Session:543  (Session)  Tribler shutdown state notification:Shutting down Video Server...
ERROR:Executor:********** TRIBLER CRASHED **********
ERROR:Executor:Tribler crashed after uptime of 19548.2940001 sec! Stack trace: Traceback (most recent call last):
File "TriblerGUI\event_request_manager.py", line 135, in on_read_data
RuntimeError: [Failure instance: Traceback: <type 'exceptions.RuntimeError'>: LZ4F_decompress failed with code: ERROR_decompressionFailed
lib\site-packages\twisted\internet\base.py:1243:run
lib\site-packages\twisted\internet\base.py:1252:mainLoop
lib\site-packages\twisted\internet\base.py:878:runUntilCurrent
lib\site-packages\twisted\internet\task.py:239:__call__
--- <exception caught here> ---
lib\site-packages\twisted\internet\defer.py:150:maybeDeferred
Tribler\Core\Libtorrent\LibtorrentMgr.py:612:_task_process_alerts
Tribler\Core\Libtorrent\LibtorrentMgr.py:408:process_alert
Tribler\Core\Libtorrent\__init__.py:17:invoke_func
Tribler\Core\Libtorrent\LibtorrentDownloadImpl.py:488:process_alert
Tribler\Core\Libtorrent\__init__.py:17:invoke_func
Tribler\Core\Libtorrent\LibtorrentDownloadImpl.py:628:on_torrent_finished_alert
Tribler\Core\Modules\gigachannel_manager.py:185:<lambda>
Tribler\Core\Modules\gigachannel_manager.py:115:on_channel_download_finished
Tribler\Core\Modules\MetadataStore\store.py:182:process_channel_dir
<auto generated wrapper of process_mdblob_file() function>:2:process_mdblob_file
lib\site-packages\pony\orm\core.py:515:new_func
Tribler\Core\Modules\MetadataStore\store.py:202:process_mdblob_file
<auto generated wrapper of process_compressed_mdblob() function>:2:process_compressed_mdblob
lib\site-packages\pony\orm\core.py:515:new_func
Tribler\Core\Modules\MetadataStore\store.py:207:process_compressed_mdblob
]

INFO:Executor:About to shutdown Tribler

# Fixed code
def on_blob(self, peer, blob):
    """
    Callback for when a MetadataBlob message comes in.

    :param peer: the peer that sent us the blob
    :param blob: payload raw data
    """
    try:
        with db_session:
            try:
                md_list = self.metadata_store.process_compressed_mdblob(blob.raw_blob)
            except (TransactionIntegrityError, CacheIndexError) as err:
                self._logger.error(
                    "DB transaction error when tried to process payload: %s", str(err)
                )
                return
    # Unfortunately, we have to catch the exception twice, because Pony can raise them both on the exit from
    # db_session, and on calling the line of code
    except (TransactionIntegrityError, CacheIndexError) as err:
        self._logger.error(
            "DB transaction error when tried to process payload: %s", str(err)
        )
        return

    # Check if the guy who send us this metadata actually has an older version of this md than
    # we do, and queue to send it back.
    with db_session:
        reply_list = [
            md
            for md, result in md_list
            if (md and (md.metadata_type == CHANNEL_TORRENT))
            and (result == GOT_NEWER_VERSION)
        ]
        reply_blob = (
            entries_to_chunk(reply_list, maximum_payload_size)[0]
            if reply_list
            else None
        )
    if reply_blob:
        self.endpoint.send(
            peer.address,
            self.ezr_pack(self.NEWS_PUSH_MESSAGE, RawBlobPayload(reply_blob)),
        )