# Buggy code
async def handle_request(self, request: BlobRequest):
    addr = self.transport.get_extra_info("peername")
    peer_address, peer_port = addr

    responses = []
    address_request = request.get_address_request()
    if address_request:
        responses.append(
            BlobPaymentAddressResponse(lbrycrd_address=self.lbrycrd_address)
        )
    availability_request = request.get_availability_request()
    if availability_request:
        responses.append(
            BlobAvailabilityResponse(
                available_blobs=list(
                    set(
                        filter(
                            lambda blob_hash: blob_hash
                            in self.blob_manager.completed_blob_hashes,
                            availability_request.requested_blobs,
                        )
                    )
                )
            )
        )
    price_request = request.get_price_request()
    if price_request:
        responses.append(BlobPriceResponse(blob_data_payment_rate="RATE_ACCEPTED"))
    download_request = request.get_blob_request()

    if download_request:
        blob = self.blob_manager.get_blob(download_request.requested_blob)
        if blob.get_is_verified():
            incoming_blob = {"blob_hash": blob.blob_hash, "length": blob.length}
            responses.append(BlobDownloadResponse(incoming_blob=incoming_blob))
            self.send_response(responses)
            blob_hash = blob.blob_hash[:8]
            log.debug("send %s to %s:%i", blob_hash, peer_address, peer_port)
            self.started_transfer.set()
            try:
                sent = await asyncio.wait_for(
                    blob.sendfile(self), self.transfer_timeout, loop=self.loop
                )
                if sent and sent > 0:
                    self.blob_manager.connection_manager.sent_data(
                        self.peer_address_and_port, sent
                    )
                    log.info(
                        "sent %s (%i bytes) to %s:%i",
                        blob_hash,
                        sent,
                        peer_address,
                        peer_port,
                    )
                else:
                    log.debug(
                        "stopped sending %s to %s:%i",
                        blob_hash,
                        peer_address,
                        peer_port,
                    )
            except (OSError, asyncio.TimeoutError) as err:
                if isinstance(err, asyncio.TimeoutError):
                    log.debug(
                        "timed out sending blob %s to %s", blob_hash, peer_address
                    )
                else:
                    log.warning(
                        "could not read blob %s to send %s:%i",
                        blob_hash,
                        peer_address,
                        peer_port,
                    )
                self.close()
            finally:
                self.transfer_finished.set()
        else:
            log.info(
                "don't have %s to send %s:%i",
                blob.blob_hash[:8],
                peer_address,
                peer_port,
            )
    if responses:
        self.send_response(responses)


# Traceback (AttributeError)
2019-08-01 18:18:06,916 INFO     lbry.stream.reflector.client:119: Sent reflector blob e5828b7e
2019-08-01 18:18:29,221 INFO     lbry.stream.reflector.client:119: Sent reflector blob 867d1a2c
2019-08-01 18:18:51,545 INFO     lbry.stream.reflector.client:119: Sent reflector blob 6e365367
2019-08-01 18:18:58,400 INFO     lbry.extras.daemon.Daemon:2330: publishing: name: xxxx params: {'title': 'xxxx', 'description': 'xxxxxx', 'bid': '0.10000000', 'languages': ['en'], 'tags': ['xxxxx'], 'thumbnail_url': 'https://spee.ch/8/xxxxxxxxx', 'license': 'All rights reserved   Published With Permission', 'release_time': 1564696220, 'channel_id': 'xxxxxxxxxxxx', 'fee_currency': 'LBC', 'fee_amount': '1.00000000', 'file_path': 'C:\\Users\\David T\\Desktop\\GMCZ0549_VID_1280x720x1500kbs_HCVC549.mp4'}
2019-08-01 18:19:22,348 ERROR    lbry.extras.daemon.Daemon:586: error handling api request
Traceback (most recent call last):
File "lbry\extras\daemon\Daemon.py", line 580, in _process_rpc_call
File "lbry\extras\daemon\Daemon.py", line 2342, in jsonrpc_publish
File "lbry\extras\daemon\Daemon.py", line 2659, in jsonrpc_stream_update
File "lbry\stream\stream_manager.py", line 232, in delete_stream
AttributeError: 'NoneType' object has no attribute 'stop_tasks'
2019-08-01 18:19:37,886 INFO     lbry.stream.reflector.client:119: Sent reflector blob f5b10e7b
2019-08-01 18:20:00,717 INFO     lbry.stream.reflector.client:119: Sent reflector blob d5ffe375

# Fixed code
async def handle_request(self, request: BlobRequest):
    addr = self.transport.get_extra_info("peername")
    peer_address, peer_port = addr

    responses = []
    address_request = request.get_address_request()
    if address_request:
        responses.append(
            BlobPaymentAddressResponse(lbrycrd_address=self.lbrycrd_address)
        )
    availability_request = request.get_availability_request()
    if availability_request:
        responses.append(
            BlobAvailabilityResponse(
                available_blobs=list(
                    set(
                        filter(
                            lambda blob_hash: blob_hash
                            in self.blob_manager.completed_blob_hashes,
                            availability_request.requested_blobs,
                        )
                    )
                )
            )
        )
    price_request = request.get_price_request()
    if price_request:
        responses.append(BlobPriceResponse(blob_data_payment_rate="RATE_ACCEPTED"))
    download_request = request.get_blob_request()

    if download_request:
        blob = self.blob_manager.get_blob(download_request.requested_blob)
        if blob.get_is_verified():
            incoming_blob = {"blob_hash": blob.blob_hash, "length": blob.length}
            responses.append(BlobDownloadResponse(incoming_blob=incoming_blob))
            self.send_response(responses)
            blob_hash = blob.blob_hash[:8]
            log.debug("send %s to %s:%i", blob_hash, peer_address, peer_port)
            self.started_transfer.set()
            try:
                sent = await asyncio.wait_for(
                    blob.sendfile(self), self.transfer_timeout, loop=self.loop
                )
                if sent and sent > 0:
                    self.blob_manager.connection_manager.sent_data(
                        self.peer_address_and_port, sent
                    )
                    log.info(
                        "sent %s (%i bytes) to %s:%i",
                        blob_hash,
                        sent,
                        peer_address,
                        peer_port,
                    )
                else:
                    self.close()
                    log.debug(
                        "stopped sending %s to %s:%i",
                        blob_hash,
                        peer_address,
                        peer_port,
                    )
                    return
            except (OSError, ValueError, asyncio.TimeoutError) as err:
                if isinstance(err, asyncio.TimeoutError):
                    log.debug(
                        "timed out sending blob %s to %s", blob_hash, peer_address
                    )
                else:
                    log.warning(
                        "could not read blob %s to send %s:%i",
                        blob_hash,
                        peer_address,
                        peer_port,
                    )
                self.close()
                return
            finally:
                self.transfer_finished.set()
        else:
            log.info(
                "don't have %s to send %s:%i",
                blob.blob_hash[:8],
                peer_address,
                peer_port,
            )
    if responses and not self.transport.is_closing():
        self.send_response(responses)