Skip to content

Fix Azure blob download close errors - #2200

Merged
stefanprodan merged 1 commit into
fluxcd:mainfrom
SebTardif:fix/azure-fgetobject-close
Oct 23, 2026
Merged

stefanprodan merged 1 commit into
fluxcd:mainfrom
SebTardif:fix/azure-fgetobject-close

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Azure Bucket downloads could publish a partial object and leak the HTTP connection.

BlobClient.FGetObject copies the DownloadStream body into a local file. On a short read, io.Copy fails and the code assigned err = f.Close(). A successful close replaced the copy error with nil, so the reconciler archived the partial object. The response body was also never closed.

GCP FGetObject already closes its reader and keeps the copy error. This matches that pattern. The download body is closed on every return, and a failed copy is returned even when closing the file succeeds. A close error after a failed copy is logged. The writable file is closed with a checked error rather than defer, so a flush failure on the success path is not dropped.

The Azure client landed in #598. DownloadStream without a body close landed in #931. The GCP close fix is #2053.

Tests

These tests failed on the previous code:

  • TestBlobClient_FGetObject_CopyError expected an error and got nil.
  • TestBlobClient_FGetObject_ClosesResponseBody left the response body open.
go test -race -count=1 -timeout 180s ./internal/bucket/azure/

That package passes after the fix. gofmt -l on the changed files is empty, and go vet ./internal/bucket/azure/ is clean.

A failed copy was reported as success when the file
close succeeded, so a partial object was archived.
The download body was also left open on every fetch.

Close the body on every return and keep the copy
error. Match the GCP FGetObject close pattern.

Assisted-by: Grok/grok-4.7
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@stefanprodan stefanprodan added bug Something isn't working area/bucket Bucket related issues and pull requests labels Oct 23, 2026

@stefanprodan stefanprodan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @SebTardif

@stefanprodan
stefanprodan merged commit bf445d6 into fluxcd:main Oct 23, 2026
9 checks passed
@SebTardif
SebTardif deleted the fix/azure-fgetobject-close branch October 23, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/bucket Bucket related issues and pull requests bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants