# Buggy code
async def readinto(self, stream):
    """Download the contents of this blob to a stream.

    :param stream:
        The stream to download to. This can be an open file-handle,
        or any writable stream. The stream must be seekable if the download
        uses more than one parallel connection.
    :returns: The number of bytes read.
    :rtype: int
    """
    # the stream must be seekable if parallel download is required
    parallel = self._max_concurrency > 1
    if parallel:
        error_message = "Target stream handle must be seekable."
        if sys.version_info >= (3,) and not stream.seekable():
            raise ValueError(error_message)

        try:
            stream.seek(stream.tell())
        except (NotImplementedError, AttributeError):
            raise ValueError(error_message)

    # Write the content to the user stream
    stream.write(self._current_content)
    if self._download_complete:
        return self.size

    data_end = self._file_size
    if self._end_range is not None:
        # Use the length unless it is over the end of the file
        data_end = min(self._file_size, self._end_range + 1)

    downloader = _AsyncChunkDownloader(
        client=self._clients.blob,
        non_empty_ranges=self._non_empty_ranges,
        total_size=self.size,
        chunk_size=self._config.max_chunk_get_size,
        current_progress=self._first_get_size,
        start_range=self._initial_range[1] + 1,  # start where the first download ended
        end_range=data_end,
        stream=stream,
        parallel=parallel,
        validate_content=self._validate_content,
        encryption_options=self._encryption_options,
        use_location=self._location_mode,
        **self._request_options,
    )

    dl_tasks = downloader.get_chunk_offsets()
    running_futures = [
        asyncio.ensure_future(downloader.process_chunk(d))
        for d in islice(dl_tasks, 0, self._max_concurrency)
    ]
    while running_futures:
        # Wait for some download to finish before adding a new one
        _done, running_futures = await asyncio.wait(
            running_futures, return_when=asyncio.FIRST_COMPLETED
        )
        try:
            next_chunk = next(dl_tasks)
        except StopIteration:
            break
        else:
            running_futures.add(
                asyncio.ensure_future(downloader.process_chunk(next_chunk))
            )

    if running_futures:
        # Wait for the remaining downloads to finish
        await asyncio.wait(running_futures)
    return self.size


# Traceback (azure.storage.blob._generated.models._models_py3.StorageErrorException)
ERROR:Task exception was never retrieved

future: <Task finished coro=<_AsyncChunkDownloader.process_chunk() done, defined at /usr/local/lib/python3.6/dist-packages/azure/storage/blob/aio/_download_async.py:53> exception=ResourceModifiedError('The condition specified using HTTP conditional header(s) is not met.\nRequestId:XXX\nTime:2020-10-06T03:09:34.2866006Z\nErrorCode:ConditionNotMet\nError:None',)>

Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/aio/_download_async.py", line 101, in _download_chunk
**self.request_options
File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/_generated/aio/operations_async/_blob_operations_async.py", line 180, in download
raise models.StorageErrorException(response, self._deserialize)
azure.storage.blob._generated.models._models_py3.StorageErrorException: Operation returned an invalid status 'The condition specified using HTTP conditional header(s) is not met.'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/aio/_download_async.py", line 55, in process_chunk
chunk_data = await self._download_chunk(chunk_start, chunk_end - 1)
File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/aio/_download_async.py", line 104, in _download_chunk
process_storage_error(error)
File "/usr/local/lib/python3.6/dist-packages/azure/storage/blob/_shared/response_handlers.py", line 147, in process_storage_error
raise error
azure.core.exceptions.ResourceModifiedError: The condition specified using HTTP conditional header(s) is not met.
Time:2020-10-06T03:09:34.2866006Z
ErrorCode:ConditionNotMet
Error:None

# Fixed code
async def readinto(self, stream):
    """Download the contents of this blob to a stream.

    :param stream:
        The stream to download to. This can be an open file-handle,
        or any writable stream. The stream must be seekable if the download
        uses more than one parallel connection.
    :returns: The number of bytes read.
    :rtype: int
    """
    # the stream must be seekable if parallel download is required
    parallel = self._max_concurrency > 1
    if parallel:
        error_message = "Target stream handle must be seekable."
        if sys.version_info >= (3,) and not stream.seekable():
            raise ValueError(error_message)

        try:
            stream.seek(stream.tell())
        except (NotImplementedError, AttributeError):
            raise ValueError(error_message)

    # Write the content to the user stream
    stream.write(self._current_content)
    if self._download_complete:
        return self.size

    data_end = self._file_size
    if self._end_range is not None:
        # Use the length unless it is over the end of the file
        data_end = min(self._file_size, self._end_range + 1)

    downloader = _AsyncChunkDownloader(
        client=self._clients.blob,
        non_empty_ranges=self._non_empty_ranges,
        total_size=self.size,
        chunk_size=self._config.max_chunk_get_size,
        current_progress=self._first_get_size,
        start_range=self._initial_range[1] + 1,  # start where the first download ended
        end_range=data_end,
        stream=stream,
        parallel=parallel,
        validate_content=self._validate_content,
        encryption_options=self._encryption_options,
        use_location=self._location_mode,
        **self._request_options,
    )

    dl_tasks = downloader.get_chunk_offsets()
    running_futures = [
        asyncio.ensure_future(downloader.process_chunk(d))
        for d in islice(dl_tasks, 0, self._max_concurrency)
    ]
    while running_futures:
        # Wait for some download to finish before adding a new one
        done, running_futures = await asyncio.wait(
            running_futures, return_when=asyncio.FIRST_COMPLETED
        )
        try:
            for task in done:
                task.result()
        except HttpResponseError as error:
            process_storage_error(error)
        try:
            next_chunk = next(dl_tasks)
        except StopIteration:
            break
        else:
            running_futures.add(
                asyncio.ensure_future(downloader.process_chunk(next_chunk))
            )

    if running_futures:
        # Wait for the remaining downloads to finish
        done, _running_futures = await asyncio.wait(running_futures)
        try:
            for task in done:
                task.result()
        except HttpResponseError as error:
            process_storage_error(error)
    return self.size