Skip to content

fix: serialize concurrent helm operations for same chart to fix #768 - #2662

Merged
yxxhero merged 1 commit into
mainfrom
fix/issue-768-concurrent-chart-download-race
Jun 25, 2026
Merged

yxxhero merged 1 commit into
mainfrom
fix/issue-768-concurrent-chart-download-race

Conversation

@yxxhero

@yxxhero yxxhero commented Jun 23, 2026

Copy link
Copy Markdown
Member

Problem

When multiple releases in a helmfile use the same remote chart (e.g. deploying platform/shell-ui as both admin-ui and agent-ui), concurrent helm upgrade/helm diff calls race on helm's internal repository cache file rename. On Windows this causes intermittent:

Error: link error: cannot rename ...\Temp\helm\repository\shell-ui-13.16.0.tgz1033128112
to ...\Temp\helm\repository\shell-ui-13.16.0.tgz: Access is denied.

The user's only workaround was --concurrency 1.

Fixes #768

Solution

Two layers of per-chart+version serialization:

1. Operation-level lock: withChartOperationLock

Wraps all SyncRelease/DiffRelease calls (4 call sites) with a mutex keyed by chart+version. Only applies to remote charts (release.ChartPath == ""); local, pre-fetched, OCI, and chartify charts bypass the lock entirely. Releases with different charts remain fully parallel.

2. Download-level lock: per-chart mutex in forcedDownloadChart/getOCIChart

Double-check locking pattern ensures only one helm fetch runs per unique chart+version within a process. Covers the ForceDownload path (lint/template/unittest/pull) and OCI charts.

Key design decisions

  • No chart path changes — helm still receives the original chart name, preserving all existing behavior and tests (zero test regressions).
  • No new flags — the fix is automatic and transparent.
  • Minimal parallelism impact — only releases sharing the same chart are serialized; different charts run fully concurrent.
  • Trade-off: the entire helm operation (download + template + deploy) is serialized for same-chart releases. This is unavoidable without pre-fetching because helm downloads and deploys atomically.

Testing

  • TestForcedDownloadChartSerializesSameChart — 5 concurrent releases, same chart → 1 Fetch call
  • TestForcedDownloadChartAllowsDifferentCharts — 2 different charts → 2 Fetch calls (not blocked)
  • TestWithChartOperationLockSerializesSameChart — verifies max concurrency = 1 for same chart
  • TestWithChartOperationLockNoLockForLocalChart — verifies local charts are NOT serialized
  • All existing tests pass with -race (0 regressions)
  • golangci-lint: 0 issues

When multiple releases in a helmfile use the same remote chart, concurrent
helm upgrade/diff calls race on helm's internal repository cache file rename,
causing intermittent 'cannot rename: Access is denied' errors on Windows.

This fix introduces two layers of serialization:

1. withChartOperationLock (operation-level): wraps SyncRelease/DiffRelease
   calls with a per-chart+version mutex. Only applies to remote charts
   (release.ChartPath is empty); local/pre-fetched/OCI charts bypass the
   lock entirely. Different charts remain fully parallel.

2. Per-chart+version download mutex in forcedDownloadChart/getOCIChart
   (download-level): uses double-check locking to ensure only one
   helm fetch runs per unique chart+version within a process.

The fix does NOT change chart paths passed to helm, preserving backward
compatibility with all existing behavior and tests.

Trade-off: same-chart releases are fully serialized (the entire helm
operation including deployment, not just download). This is unavoidable
without pre-fetching because helm downloads and deploys atomically.
Releases with different charts are unaffected.

Fixes #768

Signed-off-by: yxxhero <[email protected]>
@yxxhero
yxxhero force-pushed the fix/issue-768-concurrent-chart-download-race branch from 248a2ad to 3956f41 Compare June 23, 2026 03:42
@yxxhero
yxxhero merged commit 76613bd into main Jun 25, 2026
16 checks passed
@yxxhero
yxxhero deleted the fix/issue-768-concurrent-chart-download-race branch June 25, 2026 06:37
@SeanKilleen

Copy link
Copy Markdown

I can't tell you how excited I am about this. Thank you!

hbjydev pushed a commit to hbjydev/phoebe that referenced this pull request Jul 10, 2026
…227)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [aqua:helmfile/helmfile](https://github.com/helmfile/helmfile) | minor | `1.6.0` → `1.7.0` |

---

### Release Notes

<details>
<summary>helmfile/helmfile (aqua:helmfile/helmfile)</summary>

### [`v1.7.0`](https://github.com/helmfile/helmfile/releases/tag/v1.7.0)

[Compare Source](helmfile/helmfile@v1.6.0...v1.7.0)

#### What's Changed

- build(deps): bump azure/setup-helm from 5.0.0 to 5.0.1 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2664](helmfile/helmfile#2664)
- fix: ensure OCI charts are prepared for needed releases with --include-needs by [@&#8203;yxxhero](https://github.com/yxxhero) in [#&#8203;2663](helmfile/helmfile#2663)
- fix: serialize concurrent helm operations for same chart to fix [#&#8203;768](helmfile/helmfile#768) by [@&#8203;yxxhero](https://github.com/yxxhero) in [#&#8203;2662](helmfile/helmfile#2662)
- fix: clean up chartify temp directories after helm operations by [@&#8203;yxxhero](https://github.com/yxxhero) in [#&#8203;2668](helmfile/helmfile#2668)
- feat: add --template-args flag to template/apply/sync for helm lookup() support by [@&#8203;yxxhero](https://github.com/yxxhero) in [#&#8203;2666](helmfile/helmfile#2666)
- fix: support go-getter URLs in ad-hoc dependencies to fix [#&#8203;821](helmfile/helmfile#821) by [@&#8203;yxxhero](https://github.com/yxxhero) in [#&#8203;2670](helmfile/helmfile#2670)
- test: add integration test for issue [#&#8203;1880](helmfile/helmfile#1880) transformers with file:// deps by [@&#8203;yxxhero](https://github.com/yxxhero) in [#&#8203;2673](helmfile/helmfile#2673)
- fix: replace YAML-based DeepCopy with recursive deep copy to fix [#&#8203;973](helmfile/helmfile#973) by [@&#8203;yxxhero](https://github.com/yxxhero) in [#&#8203;2675](helmfile/helmfile#2675)
- build(deps): bump github.com/helmfile/vals from 0.44.2 to 0.44.3 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2677](helmfile/helmfile#2677)
- test: add integration test for selector filtering with requiredEnv ([#&#8203;1172](helmfile/helmfile#1172)) by [@&#8203;yxxhero](https://github.com/yxxhero) in [#&#8203;2678](helmfile/helmfile#2678)
- build(deps): bump github.com/aws/aws-sdk-go-v2/config from 1.32.25 to 1.32.26 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2681](helmfile/helmfile#2681)
- build(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.104.0 to 1.104.1 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2682](helmfile/helmfile#2682)
- feat: add `inherits:` for sub-helmfile config inheritance by [@&#8203;yxxhero](https://github.com/yxxhero) in [#&#8203;2680](helmfile/helmfile#2680)
- feat: Add ConditionTemplate support in releaseSpec by [@&#8203;agarov](https://github.com/agarov) in [#&#8203;2669](helmfile/helmfile#2669)
- build(deps): bump github.com/aws/aws-sdk-go-v2/config from 1.32.26 to 1.32.27 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2684](helmfile/helmfile#2684)
- build(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.104.1 to 1.104.2 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2685](helmfile/helmfile#2685)
- build(deps): bump github.com/helmfile/vals from 0.44.3 to 0.44.4 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2686](helmfile/helmfile#2686)

#### New Contributors

- [@&#8203;agarov](https://github.com/agarov) made their first contribution in [#&#8203;2669](helmfile/helmfile#2669)

**Full Changelog**: <helmfile/helmfile@v1.6.0...v1.7.0>

</details>

---

### Configuration

📅 **Schedule**: (in timezone Europe/London)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNDIuMSIsInVwZGF0ZWRJblZlciI6IjQzLjI0Mi4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL21pbm9yIl19-->

Reviewed-on: https://forgejo.hayden.moe/hayden/phoebe/pulls/227
toms-place added a commit to toms-place/helmfile that referenced this pull request Aug 13, 2026
…/diff (helmfile#2741)

PR helmfile#2662 fixed a Windows chart-download race (helmfile#768) by wrapping the entire
helm upgrade/diff operation in a per-chart+version lock, not just the
download. Since sync/apply/diff never set ForceDownload, releases sharing a
remote chart end up fully serialized even at high --concurrency.

Add ChartPrepareOptions.PrefetchSharedRemoteCharts: PrepareCharts groups
selected releases by chart+version, and force-downloads (once) any chart
used by 2+ releases that also resolve to identical acquisition flags
(--verify/--keyring/--plain-http/--insecure-skip-tls-verify/--devel) and to
a configured repository (or OCI ref) - not a bare \"dir/chart\"-shaped local
path. That materializes release.ChartPath, which lets withChartOperationLock's
existing ChartPath != \"\" guard skip the lock, restoring concurrency without
touching the helmfile#768 protection for charts that aren't prefetched.

Also add chartFetchFlags to give forcedDownloadChart's \`helm fetch\` the same
verify/keyring/TLS flags flagsForUpgrade already applies, closing a parity
gap that predates this change (affects lint/unittest/pull too).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Signed-off-by: Thomas Hanser <[email protected]>
toms-place added a commit to toms-place/helmfile that referenced this pull request Aug 13, 2026
…/diff (helmfile#2741)

PR helmfile#2662 fixed a Windows chart-download race (helmfile#768) by wrapping the entire
helm upgrade/diff operation in a per-chart+version lock, not just the
download. Since sync/apply/diff never set ForceDownload, releases sharing a
remote chart end up fully serialized even at high --concurrency.

Add ChartPrepareOptions.PrefetchSharedRemoteCharts: PrepareCharts groups
selected releases by chart+version, and force-downloads (once) any chart
used by 2+ releases that also resolve to identical acquisition flags
(--verify/--keyring/--plain-http/--insecure-skip-tls-verify/--devel) and to
a configured repository (or OCI ref) - not a bare \"dir/chart\"-shaped local
path. That materializes release.ChartPath, which lets withChartOperationLock's
existing ChartPath != \"\" guard skip the lock, restoring concurrency without
touching the helmfile#768 protection for charts that aren't prefetched.

Also add chartFetchFlags to give forcedDownloadChart's \`helm fetch\` the same
verify/keyring/TLS flags flagsForUpgrade already applies, closing a parity
gap that predates this change (affects lint/unittest/pull too).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Signed-off-by: Thomas Hanser <[email protected]>
yxxhero pushed a commit that referenced this pull request Aug 15, 2026
…#2743)

* fix(state): prefetch shared remote charts instead of serializing sync/diff (#2741)

PR #2662 fixed a Windows chart-download race (#768) by wrapping the entire
helm upgrade/diff operation in a per-chart+version lock, not just the
download. Since sync/apply/diff never set ForceDownload, releases sharing a
remote chart end up fully serialized even at high --concurrency.

Add ChartPrepareOptions.PrefetchSharedRemoteCharts: PrepareCharts groups
selected releases by chart+version, and force-downloads (once) any chart
used by 2+ releases that also resolve to identical acquisition flags
(--verify/--keyring/--plain-http/--insecure-skip-tls-verify/--devel) and to
a configured repository (or OCI ref) - not a bare \"dir/chart\"-shaped local
path. That materializes release.ChartPath, which lets withChartOperationLock's
existing ChartPath != \"\" guard skip the lock, restoring concurrency without
touching the #768 protection for charts that aren't prefetched.

Also add chartFetchFlags to give forcedDownloadChart's \`helm fetch\` the same
verify/keyring/TLS flags flagsForUpgrade already applies, closing a parity
gap that predates this change (affects lint/unittest/pull too).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Signed-off-by: Thomas Hanser <[email protected]>

* fix(state): exclude verify-enabled charts from shared-chart prefetch, use NUL-delimited flag signature

Copilot review on #2741's PR flagged two issues in the shared-chart prefetch
added there:

1. forcedDownloadChart untars a shared chart into a local directory, but
   flagsForUpgrade unconditionally re-adds --verify for the later `helm
   upgrade` regardless of ChartPath. Helm's VerifyChart only accepts a
   packaged .tgz/provenance pair, not an unpacked directory, so upgrading a
   prefetched chart with verify enabled would fail. Exclude --verify from
   prefetch eligibility entirely rather than trying to suppress the later
   flag - those releases just keep the pre-existing serialized-lock
   behavior, unaffected by this feature.

2. The per-key flag-agreement signature joined flags with a space, which
   isn't injective: a keyring path containing a space and a flag-like token
   could collide with a different keyring plus a real flag, silently
   deduplicating releases with different acquisition settings. Join with
   NUL instead, which can't appear in an OS argument.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Signed-off-by: Thomas Hanser <[email protected]>

* fix(state): apply -chart override before shared-chart grouping

Copilot flagged that PrepareCharts grouped releases by release.Chart
before prepareChartForRelease applied st.OverrideChart (the -chart CLI
flag), so distinct original charts that all resolve to the same
overridden chart were never recognized as shared and missed the
prefetch. Apply the override once upfront, before the grouping loop
reads release.Chart.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Signed-off-by: Thomas Hanser <[email protected]>

---------

Signed-off-by: Thomas Hanser <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
helmfile 1.7.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* build(deps): bump azure/setup-helm from 5.0.0 to 5.0.1 by @dependabot[bot] in helmfile/helmfile#2664
* fix: ensure OCI charts are prepared for needed releases with --include-needs by @yxxhero in helmfile/helmfile#2663
* fix: serialize concurrent helm operations for same chart to fix #768 by @yxxhero in helmfile/helmfile#2662
* fix: clean up chartify temp directories after helm operations by @yxxhero in helmfile/helmfile#2668
* feat: add --template-args flag to template/apply/sync for helm lookup() support by @yxxhero in helmfile/helmfile#2666
* fix: support go-getter URLs in ad-hoc dependencies to fix #821 by @yxxhero in helmfile/helmfile#2670
* test: add integration test for issue #1880 transformers with file:// deps by @yxxhero in helmfile/helmfile#2673
* fix: replace YAML-based DeepCopy with recursive deep copy to fix #973 by @yxxhero in helmfile/helmfile#2675
* build(deps): bump github.com/helmfile/vals from 0.44.2 to 0.44.3 by @dependabot[bot] in helmfile/helmfile#2677
* test: add integration test for selector filtering with requiredEnv (#1172) by @yxxhero in helmfile/helmfile#2678
* build(deps): bump github.com/aws/aws-sdk-go-v2/config from 1.32.25 to 1.32.26 by @dependabot[bot] in helmfile/helmfile#2681
* build(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.104.0 to 1.104.1 by @dependabot[bot] in helmfile/helmfile#2682
* feat: add `inherits:` for sub-helmfile config inheritance by @yxxhero in helmfile/helmfile#2680
* feat: Add ConditionTemplate support in releaseSpec by @agarov in helmfile/helmfile#2669
* build(deps): bump github.com/aws/aws-sdk-go-v2/config from 1.32.26 to 1.32.27 by @dependabot[bot] in helmfile/helmfile#2684
* build(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.104.1 to 1.104.2 by @dependabot[bot] in helmfile/helmfile#2685
* build(deps): bump github.com/helmfile/vals from 0.44.3 to 0.44.4 by @dependabot[bot] in helmfile/helmfile#2686

## New Contributors
* @agarov made their first contribution in helmfile/helmfile#2669

**Full Changelog**: https://github.com/helmfile/helmfile/compare/v1.6.0...v1.7.0</pre>
  <p>View the full release notes at <a href="https://github.com/helmfile/helmfile/releases/tag/v1.7.0">https://github.com/helmfile/helmfile/releases/tag/v1.7.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!13508
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.

Multiple instances of the same helm chart causes 'cannot rename' error with 'Access is denied.'

3 participants