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 multipart file readers not being reset when doing a retry #549

Merged

Conversation

nikplx
Copy link
Contributor

@nikplx nikplx commented Jun 15, 2022

As mentioned in #166 by @neganovalexey, when doing a retry on a multipart request the io.Reader is not reset to the start again. This can lead to subtle bugs, as the request will be retried, but the form part of the file will be empty, because the reader was already exhausted. Solving this issue in the caller code is pretty ugly, because Request does not expose access to multipartFiles and so the caller would have to use RetryHooks and recreate the Response.Request and that at each call site (where there is access to the original ReadSeeker).

In the PR, I created a new client options SetRetryResetReaders which adds a retry hook seeking the start of each reader in multipartFiles, if the reader it got also implements io.ReadSeeker. This solved the above issue described above for my usecase and should have minimal implications on existing usages.

@nikplx nikplx marked this pull request as draft June 15, 2022 10:48
@nikplx nikplx force-pushed the seek-start-for-multipart-files-on-retry branch from ee3cd94 to 6f83141 Compare June 15, 2022 11:51
@nikplx nikplx marked this pull request as ready for review June 15, 2022 11:57
@SVilgelm
Copy link
Contributor

What about the readers that cannot be reset?

@nikplx
Copy link
Contributor Author

nikplx commented Jun 21, 2022

@SVilgelm
They won't be reset. The code only resets the reader if it implements io.ReadSeeker and that only if you enable it, so as to not break any existing code. Every other reader will be untouched. I don't know if there is a usecase for passing in a reader that should not be reset, but it will not do anything if there is a reader that can not be reset.

@nikplx nikplx force-pushed the seek-start-for-multipart-files-on-retry branch from 6f83141 to bd01a8f Compare August 16, 2022 08:10
@jeevatkm
Copy link
Member

jeevatkm commented Mar 6, 2023

@nikplx I'm sorry for the delayed attention on the PR. Thanks for your contribution.

@jeevatkm jeevatkm force-pushed the seek-start-for-multipart-files-on-retry branch 2 times, most recently from 5b386fa to c027ec0 Compare March 6, 2023 00:42
@jeevatkm
Copy link
Member

jeevatkm commented Mar 6, 2023

@nikplx I'm sorry for the delayed attention on the PR. Thanks for your contribution.
Yes, it make sense to provide the reset readers option for resty users.

Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

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

@nikplx Can you please help to get the PR build validation cleared? then we can merge this PR.

@nikplx
Copy link
Contributor Author

nikplx commented Mar 6, 2023

Hey @jeevatkm

I fixed the test stage. There was some mixup in the sum file. It now runs locally. Maybe you can retrigger the pipeline if you have some time.

@jeevatkm jeevatkm force-pushed the seek-start-for-multipart-files-on-retry branch from 9b9a6ee to 7990f74 Compare March 6, 2023 09:23
@codecov
Copy link

codecov bot commented Mar 6, 2023

Codecov Report

Merging #549 (23e9fef) into master (0451c4c) will decrease coverage by 0.11%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #549      +/-   ##
==========================================
- Coverage   95.94%   95.84%   -0.11%     
==========================================
  Files          10       10              
  Lines        1357     1372      +15     
==========================================
+ Hits         1302     1315      +13     
- Misses         34       36       +2     
  Partials       21       21              
Impacted Files Coverage Δ
request.go 95.47% <ø> (ø)
client.go 97.78% <100.00%> (+0.01%) ⬆️
retry.go 100.00% <100.00%> (ø)
util.go 94.44% <0.00%> (-1.12%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jeevatkm
Copy link
Member

jeevatkm commented Mar 6, 2023

@nikplx This time PR validation build executed without any issue.

Do you mind checking this codecov feedback?

@nikplx nikplx force-pushed the seek-start-for-multipart-files-on-retry branch from 7990f74 to 23e9fef Compare March 6, 2023 11:52
Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

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

Thanks @nikplx 👍

@jeevatkm jeevatkm merged commit 15c3640 into go-resty:master Mar 8, 2023
@jeevatkm jeevatkm added this to the v2.8.0 Milestone milestone Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants