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

Retry Error in SetFileBytes(), using v3.42.1 #300

Closed
KyoungnamMin opened this issue Nov 20, 2023 · 2 comments
Closed

Retry Error in SetFileBytes(), using v3.42.1 #300

KyoungnamMin opened this issue Nov 20, 2023 · 2 comments

Comments

@KyoungnamMin
Copy link

go version: 1.21.3
req version: v3.42.1

I tried to send file bytes to the body using req SetFileBytes(). However, every time a retry was performed, I saw a case where the request failed. When I checked the server log receiving the request, the file byte length was 0.

My guess is that there is an error in the retry logic using the SetFileBytes() function. So, looking at the logic, I think that when retrying with roundTrip, the logic that sends the file seeker to the initial position of the file does not work.
Below code is writeMultipartFormFile() function in middleware.go start 66 line. I think this logic should work, but does not work in SetFileBytes() cause it's type is io.ReadCloser.

if r.RetryAttempt > 0 { // reset file reader when retry a multipart file upload
  if rs, ok := content.(io.ReadSeeker); ok {
	  _, err = rs.Seek(0, io.SeekStart)
	  if err != nil {
		  return err
	  }
  }
}

Please comment if my guess is wrong.
To solve the problem situation, we are temporarily executing SetFileBytes() every time with SetRetryHook().

imroc added a commit that referenced this issue Nov 20, 2023
@imroc
Copy link
Owner

imroc commented Nov 20, 2023

Nice catch! Fixed in the latest release, try it!

@KyoungnamMin
Copy link
Author

Thank you for quick response and resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants