-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Raise exception rather than swallowing it if there is something wrong… #16783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5665ce9
7ab97d5
9193656
b40285c
a7ac8aa
213edfb
95a867a
00e5f77
83d4219
0ede2c9
aff402b
35256ac
c73f6a6
526fca4
76a4186
3d94d8d
5c97a13
21f30ad
cd8acc6
ba3fde3
982865c
5d93063
a61c9de
207a613
f201640
5acd6b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,17 +228,24 @@ async def __anext__(self): | |
| except _ResponseStopIteration: | ||
| self.response.internal_response.close() | ||
| raise StopAsyncIteration() | ||
| except (ChunkedEncodingError, ConnectionError): | ||
| except (ChunkedEncodingError, ConnectionError) as ex: | ||
| retry_total -= 1 | ||
| if retry_total <= 0: | ||
| retry_active = False | ||
| else: | ||
| await asyncio.sleep(retry_interval) | ||
| headers = {'range': 'bytes=' + str(self.downloaded) + '-'} | ||
| resp = await self.pipeline.run(self.request, stream=True, headers=headers) | ||
| if resp.http_response.status_code == 416: | ||
| raise | ||
| chunk = await self.response.internal_response.content.read(self.block_size) | ||
| try: | ||
| resp = await self.pipeline.run(self.request, stream=True, headers=headers) | ||
| if not resp.http_response: | ||
| raise | ||
| if resp.http_response.status_code == 416: | ||
| raise | ||
| chunk = await self.response.internal_response.content.read(self.block_size) | ||
|
xiangyan99 marked this conversation as resolved.
Outdated
|
||
| except Exception as err: # pylint: disable=broad-except | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious - prior to your change - which
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It fails in https://github.com/psf/requests/blob/master/requests/models.py#L920, self.status_code is None. |
||
| _LOGGER.warning("Unable to stream download: %s", err) | ||
| self.response.internal_response.close() | ||
| raise ex | ||
| if not chunk: | ||
| raise StopAsyncIteration() | ||
| self.downloaded += len(chunk) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,17 +130,24 @@ def __next__(self): | |
| self.response.internal_response.close() | ||
| raise StopIteration() | ||
| except (requests.exceptions.ChunkedEncodingError, | ||
| requests.exceptions.ConnectionError): | ||
| requests.exceptions.ConnectionError) as ex: | ||
| retry_total -= 1 | ||
| if retry_total <= 0: | ||
| retry_active = False | ||
| else: | ||
| time.sleep(retry_interval) | ||
| headers = {'range': 'bytes=' + str(self.downloaded) + '-'} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm starting to repeat myself at least 3 times over, but again: the original request saved in Also note that there are REST APIs that have special range request headers that take precedence over So it would not even help to try parse this header of the original request here, because one can never be sure to catch all the special cases of APIs here. Again, please do not retry, this cannot be done safely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should also add that, in general and sometimes as Both of them can be wrong, in general: requests configures urllib3 to do decoding based on the content-encoding header of the response (e.g. gunzip the data stream): However, note that urllib3's So in essence, there is no way to reliably know how many of the original bytes were downloaded unless it's clear there is the special case of no http response chunking and no content decoding, and relying on implementation details of urllib3.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @xiangyan99, regarding the real word scenarios. We are using the azure blob storage in our machine learning applications that pull parquet data from the azure blob storage. Parquet files implement row group statistics, so a common optimisation is to only read the parts of the parquet file that have the row group statistics and then do pruning based on predicates. See https://github.com/mbr/simplekv/blob/master/simplekv/net/_azurestore_new.py#L194 for a file like interface to access the azure blob storage and http://peter-hoffmann.com/2020/understand-predicate-pushdown-on-rowgroup-level-in-parquet-with-pyarrow-and-python.html or an explanation about row group pruning.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @jochen-ott-by @hoffmann , your information is really helpful. Let me re-think about it. :) |
||
| resp = self.pipeline.run(self.request, stream=True, headers=headers) | ||
| if resp.http_response.status_code == 416: | ||
| raise | ||
| chunk = next(self.iter_content_func) | ||
| try: | ||
| resp = self.pipeline.run(self.request, stream=True, headers=headers) | ||
| if not resp.http_response: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't recall that the HttpResponse object had a boolean value? Or will this value be None under some circumstances?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| raise | ||
| if resp.http_response.status_code == 416: | ||
| raise | ||
| chunk = next(self.iter_content_func) | ||
|
xiangyan99 marked this conversation as resolved.
Outdated
|
||
| except Exception as err: # pylint: disable=broad-except | ||
| _LOGGER.warning("Unable to stream download: %s", err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional nit:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to be consistent to https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/azure/core/pipeline/transport/_requests_basic.py#L152. But I am open to change it. |
||
| self.response.internal_response.close() | ||
| raise ex | ||
| if not chunk: | ||
| raise StopIteration() | ||
| self.downloaded += len(chunk) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.