-
Notifications
You must be signed in to change notification settings - Fork 261
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: executeWithRetry, save the request body and write the body to th… #296
Conversation
…e request before we process it
numRetry := 0 | ||
for { | ||
// update body | ||
req.Body = ioutil.NopCloser(bytes.NewBuffer(body)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't you need to close this req.Body at some point in the loop? (If not, why doing the req.Body.Close() line 208?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, I need to close the body of the request. I change the code and use defer req.Body.Close(). The request Body needs to be closed immediately after reading it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you should defer it because you're in the infinite loop that can override multiple times req.Body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, since the defer is executed when the surrounding function returns, it will not execute when the body is updated. I will close the req.Body after reading or updating it.
…ody in an infinite loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be worth doing a simple test sending 100ks http queries in a short amount of time to chproxy to be sure there are no side effects
I will add one test in the main_test.go file. |
ff1e2d2
to
5e2158e
Compare
…e request before we process it
Description
#293
The req.Body could only be read once, so when we retry the query, the body is empty, which will lead to a 400 error.
Pull request type
Please check the type of change your PR introduces:
Checklist
Does this introduce a breaking change?
Further comments