diff --git a/.chloggen/goleak_internalazure.yaml b/.chloggen/goleak_internalazure.yaml new file mode 100644 index 0000000000000..02da1a24b6e10 --- /dev/null +++ b/.chloggen/goleak_internalazure.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: processor/resourcedetection, exporter/datadog + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix memory leak on AKS + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [32574] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/internal/metadataproviders/azure/metadata.go b/internal/metadataproviders/azure/metadata.go index b6241feab8691..54f73d3a27d70 100644 --- a/internal/metadataproviders/azure/metadata.go +++ b/internal/metadataproviders/azure/metadata.go @@ -74,12 +74,13 @@ func (p *azureProviderImpl) Metadata(ctx context.Context) (*ComputeMetadata, err resp, err := p.client.Do(req) if err != nil { return nil, fmt.Errorf("failed to query Azure IMDS: %w", err) - } else if resp.StatusCode != 200 { + } + defer resp.Body.Close() + if resp.StatusCode != 200 { //lint:ignore ST1005 Azure is a capitalized proper noun here return nil, fmt.Errorf("Azure IMDS replied with status code: %s", resp.Status) } - defer resp.Body.Close() respBody, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read Azure IMDS reply: %w", err) diff --git a/internal/metadataproviders/azure/package_test.go b/internal/metadataproviders/azure/package_test.go new file mode 100644 index 0000000000000..c7b9e1e8dda90 --- /dev/null +++ b/internal/metadataproviders/azure/package_test.go @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package azure + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +}