Skip to content

chore: add support for bodyclose #2190

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

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ linters:
- asasalint # check for pass []any as any in variadic func(...any) [fast: false, auto-fix: false]
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
- contextcheck # check the function whether use a non-inherited context [fast: false, auto-fix: false]
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
Expand Down
7 changes: 5 additions & 2 deletions api/instance/v1/instance_metadata_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (meta *MetadataAPI) getMetadataURL() string {
meta.MetadataURL = &url
return url
}
defer resp.Body.Close()
}
return metadataAPIv4
}
Expand Down Expand Up @@ -264,11 +265,12 @@ func (meta *MetadataAPI) SetUserData(key string, value []byte) error {
return errors.Wrap(err, "error creating patch userdata request")
}
request.Header.Set("Content-Type", "text/plain")
_, err = userdataClient.Do(request)
resp, err := userdataClient.Do(request)
if err != nil {
retries++ // retry with a different source port
continue
}
defer resp.Body.Close()

return nil
}
Expand Down Expand Up @@ -302,11 +304,12 @@ func (meta *MetadataAPI) DeleteUserData(key string) error {
if err != nil {
return errors.Wrap(err, "error creating delete userdata request")
}
_, err = userdataClient.Do(request)
resp, err := userdataClient.Do(request)
if err != nil {
retries++ // retry with a different source port
continue
}
defer resp.Body.Close()

return nil
}
Expand Down