Skip to content

fix: Return copies of the cached maps, not the live ones - #196

Merged
gianlucam76 merged 1 commit into
projectsveltos:mainfrom
gianlucam76:fix-concurrent-map-iteration
Oct 19, 2026
Merged

gianlucam76 merged 1 commit into
projectsveltos:mainfrom
gianlucam76:fix-concurrent-map-iteration

Conversation

@gianlucam76

Copy link
Copy Markdown
Member

GetManagedSveltosClusters, GetManagedCAPIClusters, GetClusterProfileStatuses and GetProfiles returned the cached map itself. The read lock was released on return, so the HTTP handlers iterated the map without any lock while the controllers kept updating it. Go aborts the process on a concurrent map iteration and write: with SveltosClusters being updated while clients listed clusters, ui-backend crashed with "fatal error: concurrent map iteration and map write".

The getters now return a copy made while holding the lock.

The RemoveProfile spec kept a map obtained before the removal and relied on it being the live cache. It now reads the profiles again after the removal.

GetManagedSveltosClusters, GetManagedCAPIClusters, GetClusterProfileStatuses and
GetProfiles returned the cached map itself. The read lock was released on return,
so the HTTP handlers iterated the map without any lock while the controllers kept
updating it. Go aborts the process on a concurrent map iteration and write: with
SveltosClusters being updated while clients listed clusters, ui-backend crashed
with "fatal error: concurrent map iteration and map write".

The getters now return a copy made while holding the lock.

The RemoveProfile spec kept a map obtained before the removal and relied on it
being the live cache. It now reads the profiles again after the removal.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@gianlucam76
gianlucam76 merged commit 7356b4e into projectsveltos:main Oct 19, 2026
5 checks passed
@gianlucam76
gianlucam76 deleted the fix-concurrent-map-iteration branch October 19, 2026 08:49
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.

1 participant