fix: retries don't properly populate response data #107
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
summary:
the knox client would not return the proper data when a retry is performed, this is due to how it handles outparam passing
the full lifecycle of the how knox handles retrieving data from the AddVersion request:
var i uint64
getHTTPData
getHTTPResp
getHTTPResp
JSON unmarshals into the outparam in Response-- this is where the bug occurs, the current implementation relies on Unmarshal writing to the pointer stored in Response however if the respones is nil (which is what occurs when the server returns an internal error), it will overwrite the pointer in the struct with
nil
Data
is nil so it will just write to it, not the outparameterAddVersion
doesn't have the outparami
updated which causes it to return with the default value of 0fix:
the fix checks if the Data field of the Response wrapper is nil, if so then it sets it back to what it was before the Unmarshal was done
future:
the cause of this bug was outparameter passing and the reliance on the behavior with JSON unmarshal. this is easy to miss in the code (especially with the abundant use of
interface{}
) and it may be a good idea to replace this with generics