Repository navigation
Track engaged clusters atomically and keep re-engaged clusters - #213
Conversation
The cluster tracker read its map without holding the lock, so concurrent Engage() calls could crash the agent with a concurrent map read and map write. It also only recorded a cluster if no entry existed yet: when a cluster was engaged again with a new context, the tracker kept the old engagement, and once that ended the entry was deleted although the cluster was still engaged. Sync controllers started afterwards were not pre-seeded with that cluster. Check and set the entry under the lock, replace it when the context or the cluster changes, and let an ended engagement only remove its own entry. on-behalf-of: @eon-se opensource@eon.com Signed-off-by: Mark Altmann <mark.altmann.external@eon.com>
A late Engage() whose context is already cancelled must neither replace the tracked engagement nor be forwarded: a controller would cancel its live engagement in favour of the ended one when the cluster differs. on-behalf-of: @eon-se opensource@eon.com Signed-off-by: Mark Altmann <mark.altmann.external@eon.com>
|
Hi @Wompipomp. Thanks for your PR. I'm waiting for a kcp-dev member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
|
@mjudeikis-bot review please |
mjudeikis-bot
left a comment
There was a problem hiding this comment.
Verified: I built internal/kcp and ran go vet on it, both cleanly. I ran the three new tests under go test -race -count=5 on the PR head, and all passed with no race reports. I also copied the new test file into an extracted base tree (915bacb) and ran it there with -race. It reported 3 DATA RACE warnings, and TestConcurrentClusterEngagements and TestReEngagedClusterStaysTracked failed. So the tests reproduce both the unlocked map read and the deletion of a re-engaged cluster, and the change fixes both. I also compared the dedup rule with mcController.Engage in multicluster-runtime v0.24.1, and the lock order between StartController (runnablesLock, then the tracker lock) and Engage (tracker lock released before runnablesLock). I found no deadlock or new ordering problem. I did not run an end-to-end check against a real kcp, because the sandbox has none. The change is correct and well-scoped. The only gap is that no test covers the new rule that ended engagements are not forwarded to controllers.
| // a late Engage() for an engagement that has already ended must neither replace the | ||
| // tracked engagement nor be forwarded, as a controller would cancel its live engagement | ||
| // in favour of the ended one if the cluster differs | ||
| if ctx.Err() != nil { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Note: The early return for an already-cancelled ctx also stops the call from being forwarded to running controllers. The comment says this forwarding is the main reason for the check: a controller would otherwise cancel its live engagement in favour of the ended one. No test covers it, though. newTestDMCM leaves runnables nil, so TestEndedEngagementDoesNotReplaceLiveOne only checks the tracker map, and that test also passed at the base commit. Add a test that registers a fake mcmanager.Runnable in dmcm.runnables and asserts its Engage is not called for the cancelled ctx.
|
/lgtm |
|
LGTM label has been added. DetailsGit tree hash: 72a4421ca5cb642fd144c049eb615eb58f138d0e |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mjudeikis The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest |
1 similar comment
|
/retest |
Summary
clusterTracker.Engage()read its map without holding the lock (a concurrent map read and mapwrite can crash the agent), and it only recorded a cluster if no entry existed yet. When a cluster
was engaged again with a new context, the tracker kept the old engagement; once that ended, the
entry was deleted although the cluster was engaged again, and sync controllers started later were
not pre-seeded with it.
The entry is now checked and set under the lock and replaced when the context or the cluster
changes. Each engagement removes the entry only if it is still its own (via
context.AfterFuncinstead of a goroutine per engagement). Forwarding the engagement to the running controllers is
unchanged and still happens outside the tracker lock. A late
Engage()with an already cancelledcontext is ignored, so it neither replaces the live entry nor (for a different cluster object)
cancels the live engagement in the running controllers.
Tested with
go test -race ./...,make lintandmake test-e2e(kcp 0.32). Three new unit tests: concurrent engagements(fails under
-racewithout the fix), a re-engaged cluster that must stay tracked after itsprevious engagement ends (fails without the fix), and a late engagement with a cancelled context
that must not replace the live one (guards the replace logic introduced here; fails with only the
first commit).
Independent of #191, #201, #212 and #211; the branch merges cleanly with each of them.
What Type of PR Is This?
/kind bug
Related Issue(s)
Fixes #209
Release Notes