Skip to content
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

Fix: Reset stream on retries #285

Closed
wants to merge 2 commits into from

Conversation

fboismenu
Copy link

@fboismenu fboismenu commented Oct 26, 2021

Fixes #284
Reset download stream before processing a retried request.
Avoids to accumulate data from a failed request.

@fboismenu fboismenu requested review from a team as code owners October 26, 2021 18:58
@google-cla
Copy link

google-cla bot commented Oct 26, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/google-resumable-media-python API. label Oct 26, 2021
@google-cla google-cla bot added the cla: no This human has *not* signed the Contributor License Agreement. label Oct 26, 2021
@fboismenu
Copy link
Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Oct 26, 2021
@fboismenu fboismenu changed the title Fix #284: Reset stream on retries Fix: Reset stream on retries Oct 26, 2021
Fixes Issue googleapis#284.

Reset Download _stream on retry to avoid accumulating data from
previous failed request.
Copy link
Contributor

@tseaver tseaver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fboismenu Thanks very much for the patch! In additional to my inline comments, we also need to address the following concerns:

  • In order to demonstrate the fix, we need new unit tests which provoke retries after a write to the stream, and which assert that the stream does not contain that initial write after finishing the download.
  • We need to consider how the fix generalizes to the other two classes (ChunkedDownload and RawChunkedDownload).

def retriable_request():

nonlocal is_retry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty uncomfortable with nonlocal here -- I'd rather define / depend on an attribute of the Download instance.


nonlocal is_retry
if is_retry and self._stream is not None:
self._stream.seek(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._stream is documented only to be a "A write-able stream (i.e. file-like object)" -- we have no guarantee that it is seekable.

@cojenco cojenco assigned cojenco and unassigned fboismenu Jan 10, 2022
@cojenco
Copy link
Contributor

cojenco commented Jan 10, 2022

Hi, I'm working on submitting a fix, and will link the new PR back to this. Thanks!

@parthea
Copy link
Contributor

parthea commented Jan 18, 2022

Superseded by #294

@parthea parthea closed this Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/google-resumable-media-python API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stream reset on retry
4 participants