-
Notifications
You must be signed in to change notification settings - Fork 2k
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 returned EOF error when calling Nodes GC/GcAlloc API #5970
Conversation
@langmartin it looks like the requested changes were made, but I can't get Travis to rebuild it because we've removed the scripts for Travis since this was last pushed. Maybe if @jrasell would be willing to squash his commits and re-push, it'll trigger CircleCI and we can get this merged? |
Yes! @jrasell the age on this is my fault, it got mixed up with some followup work: we shouldn't be using side effecting |
The API decodeBody function will now check the content length before attempting to decode. If the length is zero, and the out interface is nil then it is safe to assume the API call is not returning any data to the user. This allows us to better handle passing nil to API calls in a single place.
@@ -930,8 +931,16 @@ func parseWriteMeta(resp *http.Response, q *WriteMeta) error { | |||
|
|||
// decodeBody is used to JSON decode a body | |||
func decodeBody(resp *http.Response, out interface{}) error { |
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.
Should we always skip decoding body if out == nil
? I noticed that we wrap few decodeBody
invocations with a nil check already:
Lines 858 to 862 in d890ddb
if out != nil { | |
if err := decodeBody(resp, &out); err != nil { | |
return nil, err | |
} | |
} |
It would simplify caller code a bit, and it doesn't seem like an error if caller explicitly passes nil and ignores response body (though body may need to be consumed... a potential bug in current code).
Update CHANGELOG.md with #5970 entry.
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
Internally Nomad returns a http.NoBody when calling nodes GC, therefore attempting to decode the body results in an EOF error returned to the user. This fix updates the decodeBody function to check both the response content length and the passed out object.
The following code snippet can be used to locally test:
Closes #5506 #5994