Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
DeleteTarget only released the cluster lock from inside the branch that removes the target from the runtime map, so a target that exists in the config but not in the runtime map returned without unlocking and without error. The API reported success while the lock stayed held. That is the state a collector is in after a restart: it holds locks for targets it has not recreated yet, and its fresh runtime map is empty. Every such lock became a ghost that a later DELETE against the same config could not clear, because that delete also took the non-running branch. The lock is held against the config rather than the runtime target, so it is now released after the runtime cleanup, on both paths. The close and delete of a running target are unchanged, and an unlock error is still returned. Also drop the target's entry from targetsLockFn. The cancel func was invoked but the map entry stayed, so the target continued to be reported as an assignment after it was deleted.
methakon
force-pushed
the
fix/1011-delete-target-releases-lock
branch
from
September 29, 2026 19:18
8351c82 to
5b75259
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DELETE /api/v1/config/targets/{name}returns200and removes the target from the config, but thecluster lock is only released from inside the branch that removes the target from the runtime
map:
A target that is in the config but not in the runtime map therefore returns success having released
nothing.
That is exactly the state a collector is in after a restart: it holds locks for targets it has not
recreated yet, and its fresh runtime map is empty. Every lock carried across a restart became a
ghost, and no subsequent DELETE could clear it, because that delete also took the non-running branch.
This is why the report describes the bug as invisible within a single instance lifetime and only
surfacing after a restart.
There is a second, independent leak: the assignment entry in
targetsLockFnhas its cancel funcinvoked but is never removed from the map, so it continues to be reported as a live assignment for a
deleted target.
Change
lock is held against the config, not against the runtime target, which is what makes that correct
delete(a.targetsLockFn, name)alongside the existingcfn()callClosing and removing a running target is unchanged.
Test
target_delete_lock_test.gouses a locker that records the keys passed toUnlock:TestDeleteTargetUnlocksWhenTargetNotRunningTestDeleteTargetRemovesLockAssignmentTestDeleteTargetClosesRunningTargetTestDeleteTargetUnknownStillErrorsThe first two fail against the unfixed handler, which is the evidence that they pin the reported
behaviour rather than the implementation:
Verification
go test ./pkg/app/... -count=1go test ./pkg/app/ -run TestDeleteTarget -count=1go vet ./pkg/app/gofmt -lon both filesThe tests drive
App.DeleteTargetdirectly rather than going through the REST handler, so they donot need a running collector or a consul instance. I have not exercised the HTTP path end to end;
the handler is a thin wrapper that calls this method.
Fixes #1011