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: retries don't properly populate response data #107

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jimmyl02
Copy link
Contributor

@jimmyl02 jimmyl02 commented Jul 18, 2024

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:

  1. creates outparam var i uint64
  2. passes into getHTTPData
  3. http request, client, and outparam wrapped in Response are passed to getHTTPResp
  4. 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
  5. upon retry, the JSON unmarshal will see that the value in Data is nil so it will just write to it, not the outparameter
  6. the calling function AddVersion doesn't have the outparam i updated which causes it to return with the default value of 0

fix:
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

@jimmyl02 jimmyl02 changed the title feat: add a concurrency test fix: retries don't properly populate response data Jul 18, 2024
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

Successfully merging this pull request may close these issues.

2 participants