Skip to content

Remove leaked Helm index cache on error - #2201

Merged
matheuscscp merged 1 commit into
fluxcd:mainfrom
SebTardif:fix/helm-index-temp-leak
Oct 23, 2026
Merged

matheuscscp merged 1 commit into
fluxcd:mainfrom
SebTardif:fix/helm-index-temp-leak

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

ChartRepository.CacheIndex writes chart-index-*.yaml under the controller temp directory and documents that the caller removes it. reconcileArtifact does that in a defer. reconcile stops on the first error, so three reconcileSource returns never reach that defer:

  • the index downloads with HTTP 200, then LoadFromPath rejects it
  • revision calculation fails
  • the status patch fails

Each failed reconcile leaves the file until the pod restarts. The controller points TMPDIR at its own temp root, and startup purge only removes leftovers from the previous process.

This removes the cached index on those three returns. A successful fetch, including the unchanged-revision short circuit, still leaves the file for reconcileArtifact. A close error is logged with the same message reconcileArtifact already uses, and it does not replace the original reconcile error.

The leak was reported in #1451 and #1462. #1457 refuses to keep an index larger than the maximum size, which covers the oversized file those issues described. An HTTP 200 body that is not a valid Helm index, and a later status patch failure, still left the file. The returns without removal come from #1001.

#824 and #2063 change the error text for an invalid repository. They do not remove the temp file.

Tests

TestHelmRepositoryReconciler_reconcileSource_cachedIndexFile sets TMPDIR to a private directory and globs chart-index-*.yaml.

On the previous code, the invalid-index and status-patch cases returned the expected errors and still left a chart-index-*.yaml file. The successful fetch already kept the file.

After this change, the two error cases leave no chart-index-*.yaml file, and the successful fetch still keeps chartRepo.Path.

CacheIndex writes chart-index-*.yaml under the controller temp
directory and leaves removal to the caller. reconcileArtifact
deletes that file, but reconcile returns on the first error, so
a failed index load, revision calculation, or status patch never
reaches it. Each failed reconcile keeps the file until the pod
restarts.

Remove the cached index on those three returns. Leave it in place
when reconcileSource succeeds, including the unchanged-revision
short circuit, because reconcileArtifact still needs the file.

Assisted-by: Grok/grok-4.7
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>

@matheuscscp matheuscscp 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

@matheuscscp
matheuscscp merged commit d18f29c into fluxcd:main Oct 23, 2026
7 checks passed
@SebTardif
SebTardif deleted the fix/helm-index-temp-leak 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants