# Buggy code
async def reflect_streams(self):
    while True:
        if self.config.reflect_streams and self.config.reflector_servers:
            sd_hashes = await self.storage.get_streams_to_re_reflect()
            sd_hashes = [sd for sd in sd_hashes if sd in self.streams]
            batch = []
            while sd_hashes:
                stream = self.streams[sd_hashes.pop()]
                if (
                    self.blob_manager.is_blob_verified(stream.sd_hash)
                    and stream.blobs_completed
                ):
                    if not stream.fully_reflected.is_set():
                        host, port = random.choice(self.config.reflector_servers)
                        batch.append(stream.upload_to_reflector(host, port))
                if len(batch) >= self.config.concurrent_reflector_uploads:
                    await asyncio.gather(*batch, loop=self.loop)
                    batch = []
            if batch:
                await asyncio.gather(*batch, loop=self.loop)
        await asyncio.sleep(300, loop=self.loop)


# 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 reflect_streams(self):
    while True:
        if self.config.reflect_streams and self.config.reflector_servers:
            sd_hashes = await self.storage.get_streams_to_re_reflect()
            sd_hashes = [sd for sd in sd_hashes if sd in self.streams]
            batch = []
            while sd_hashes:
                stream = self.streams[sd_hashes.pop()]
                if (
                    self.blob_manager.is_blob_verified(stream.sd_hash)
                    and stream.blobs_completed
                    and stream.sd_hash not in self.running_reflector_uploads
                    and not stream.fully_reflected.is_set()
                ):
                    batch.append(self.reflect_stream(stream))
                if len(batch) >= self.config.concurrent_reflector_uploads:
                    await asyncio.gather(*batch, loop=self.loop)
                    batch = []
            if batch:
                await asyncio.gather(*batch, loop=self.loop)
        await asyncio.sleep(300, loop=self.loop)