Repository navigation
Release cluster engagements and event handlers of stopped sync controllers - #212
Conversation
|
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. |
dfac077 to
b014641
Compare
|
/ok-to-test |
This comment was marked as outdated.
This comment was marked as outdated.
|
@mjudeikis-bot review. Im looking for breaking changes. Be short and consise |
mjudeikis-bot
left a comment
There was a problem hiding this comment.
Verified: go build ./... and go vet ./internal/... both pass. I ran go test -race on internal/kcp, internal/controllerutil, internal/controller/syncmanager and internal/controller/sync, and all passed. I then ran the new kcp tests 5 more times with the race detector (-count=5) and TestSyncControllerRecovery 3 more times (-count=3); none were flaky. To check that TestStoppedControllersDoNotLeak tests what it claims, I removed the HandlerRemovingCache wrapper from it. It then failed with "expected goroutines to return to baseline 17 after 20 controller restarts, got 57", which shows it catches the leak. I could not run an end-to-end test against a real kcp cluster in this sandbox.
The change is correct as far as I checked. controller-runtime v0.24.1's Kind source calls GetInformer with the same context it was started with (passed through PollUntilContextCancel), and that context is also cancelled when WaitForSync times out. So tying handler removal to that context is sound. Both local-side source.TypedKind watches in the sync controller are wrapped, and the AfterFunc chaining in dynamicRunnable.engage ends the engagement when either the cluster or the controller stops, without leaving AfterFuncs behind. I have no findings.
|
/lgtm |
|
LGTM label has been added. DetailsGit tree hash: 89b39ef5fdcd38574444018f22c87d264541431c |
|
/retest |
1 similar comment
|
/retest |
…llers When the sync manager stops a sync controller, it cancels the controller's context, but two things kept the stopped controller alive: * The DynamicMultiClusterManager forwarded Engage() with the cluster's context only, so multicluster-runtime kept every stopped controller engaged (a cluster map entry plus a goroutine holding the whole controller) until the workspace disconnected. Engagements now also end when the controller's own context is cancelled. * controller-runtime's Kind source never removes its event handler from the shared informer, so every stopped controller left a handler (and two listener goroutines) behind on the local manager's informers. The local primary and related-resource watches now use a cache wrapper that removes each handler once the context the informer was requested with ends; for Kind sources that is a child of their start context. The kcp-side sources already do this (multicluster-runtime's Kind source). A new test starts and stops a controller wired like a sync controller 20 times and checks that the goroutine count returns to its baseline. The sync manager's restart test now also checks that the local event handler of its sync controller is removed once the controller stops (its test informer gains a RemoveEventHandler for that). on-behalf-of: @eon-se opensource@eon.com Signed-off-by: Mark Altmann <mark.altmann.external@eon.com>
b014641 to
74b61b3
Compare
|
Rebased onto |
|
/lgtm |
|
LGTM label has been added. DetailsGit tree hash: 80a2726521a0ba748237a5bbe0ac5da735f3d36c |
|
[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 |
Summary
When the sync manager stops a sync controller, it cancels the controller's context, but the
controller stayed reachable in two places, so neither it nor its goroutines were released. Since
#201, every failed start and every unexpected exit stops a controller; with #211 every
PublishedResource update does as well.
DynamicMultiClusterManagerpassed only the cluster's context toEngage(). The engagement inmulticluster-runtime lasts until that context is done, so a stopped controller stayed engaged
with every workspace until the workspace disconnected. The DMCM now derives the engagement
context from both the cluster's and the controller's context, for regular engagements and for
pre-seeding alike.
source.Kindnever removes its handler from the shared informer. The localwatches of a sync controller (primary object and related resources) now go through a small cache
wrapper (
controllerutil.HandlerRemovingCache) that removes each registered handler (for allAddEventHandler*variants) once the context the informer was requested with ends. ForKindsources this is a child of their start context, so it ends with the controller (and also when
the source's cache sync times out). The kcp-side watches already behave like this.
Assumption: the wrapper relies on
source.KindcallingGetInformerwith its start context, whichis the case in controller-runtime v0.24. If that changes, the new leak test catches it.
Tested with
go test -race ./...andmake lint(no new findings) after the rebase; e2e runs in CI.TestStoppedControllersDoNotLeakstarts and stops such a controller 20 times and checks that thegoroutine count returns to its baseline; it fails without either part of the fix (+20 goroutines
without the engagement fix, +40 without the handler removal). Unit tests for the engagement
lifetime and for the cache wrapper are included. #201's
TestSyncControllerRecoverynow alsochecks that the local event handler is removed when the controller stops (its test informer gets a
RemoveEventHandlerfor that).Rebased onto
mainafter #201 and #194 (the new service-side related-resource watch also uses thewrapper).
What Type of PR Is This?
/kind bug
Related Issue(s)
Fixes #208
Release Notes