Skip to content

fix: release OCM resource handles after fetching and localization - #1026

Merged
jakobmoellerdev merged 1 commit into
open-component-model:mainfrom
c5426746:fix/resource-handle-cleanup
Oct 17, 2026
Merged

jakobmoellerdev merged 1 commit into
open-component-model:mainfrom
c5426746:fix/resource-handle-cleanup

Conversation

@c5426746

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

Fix missing cleanup of OCM component version handles and resource access methods during resource fetching and localization. Repeated reconciliations can retain references to component and repository state after the operation has finished.

ResolveResourceReference returns an owned component version handle, including a duplicated handle when the reference path is empty. Both GetResource and the localization resolver discarded this handle. Closing the caller's original component version does not release that additional reference.

This change closes the resolved handle when either operation returns, including error paths. Resource readers also retain their access method until the reader is closed, and close the method immediately if opening the reader fails. Any cleanup error on that failure path is joined with the original error.

Validation

  • Added regression tests for resource fetching and localization on success and error paths, and access-method lifetime while a resource reader is in use.
  • A regression test using a local OCM CTF repository performs 100 localization lookups and checks the component reference count. Before the fix it rises from 1 to 101; with the fix it remains at 1.
  • All four regression tests fail against unmodified current main and pass with this change.
  • GOTOOLCHAIN=go1.26.8 go test ./pkg/ocm ./controllers -count=1 passes.
  • GOTOOLCHAIN=go1.26.8 make lint reports zero issues.

Controller evidence

This issue was investigated in a Kubernetes deployment running ocm-controller v0.33.0. The attached before/after charts show CPU dropping from roughly 1.5–1.7 cores to 0.7–0.8 cores. Memory grows much more slowly, remaining around 0.5–0.8 GB during the post-deployment observation window, compared with repeated climbs above 2 GB beforehand.

The controller used for this comparison includes these cleanup fixes and the separate SDK finalizer-cycle fix in open-component-model/ocm#2144. The charts show their combined effect; the regression tests above isolate the controller cleanup defects. Some gradual memory growth remains visible, so these observations do not establish that every source of growth is resolved.

Controller CPU and memory before and after the combined fixes

cc @Skarlso @dee0sap

Which issue(s) this PR is related to

Related to open-component-model/ocm-project#778 — memory leak in ocm controller 0.27.3.

Previous controller cleanup work: open-component-model/ocm-controller#799.

Related SDK fix: open-component-model/ocm#2144.

Close component version handles returned by resource resolution in GetResource and localization, including downstream error paths. Tie access method cleanup to resource readers and close the method if opening the reader fails.

Add ownership regression tests and a local CTF reference-count test covering repeated localization lookups.

Signed-off-by: Theodore Siemens-Rhodes <theodore.siemens-rhodes@sap.com>
@c5426746
c5426746 marked this pull request as ready for review October 16, 2026 23:38
@c5426746
c5426746 requested a review from a team as a code owner October 16, 2026 23:38
@jakobmoellerdev
jakobmoellerdev merged commit 7dfc54a into open-component-model:main Oct 17, 2026
9 checks passed
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