fix: address semaphore/mutex unsoundness for Initalize#16160
Open
isubasinghe wants to merge 2 commits into
Open
fix: address semaphore/mutex unsoundness for Initalize#16160isubasinghe wants to merge 2 commits into
isubasinghe wants to merge 2 commits into
Conversation
Signed-off-by: isubasinghe <isitha@pipekit.io>
Signed-off-by: isubasinghe <isitha@pipekit.io>
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.
Motivation
On restart the controller rebuilds its in-memory lock map from the holders that Running workflows record in their status. The old
Initializesilently dropped any holder it couldn't re-establish. A racing workflow'stryAcquirethen finds the lock absent, makes a fresh one, and acquires a lock that persisted state says is already held. For a mutex that means two workflows running at once under the same mutex.Modifications
reacquireto thesemaphoreinterface. It re-establishes a recorded holder ignoring the current limit, so if the limit was lowered below the live holder count, new acquirers wait for the count to drain rather than aholder getting dropped.
Initializenow returns an error, and the controller fails closed (won't start) when a holder can't be recovered at all: an undecodable lock name, or a database-backed hold with no DB session.poisonedLockthat refuses every acquire and reports a message on the waiting node's sync status. It lives inmemory only and clears on the next restart, when
Initializere-evaluates.Verification
go test ./workflow/sync/.... Unit tests insync_manager_test.gocover the fatal, poison, and reacquire paths, includingInitializeLoweredLimitForceRegistersAllHoldersfor the in-memory (ConfigMap) semaphore andTestDatabaseInitializeLoweredLimitAfterRestartfor the database-backed one (Postgres and MySQL via testcontainers): two workflows acquire under limit 2, the limit drops to 1, the controller restarts, both keep their locks,and a new contender waits until the holders drain below the limit.
Documentation
Not needed. This is internal controller restart behavior with no user-facing API, CRD, or config change.
AI
Claude Code (Opus 4.8) was used to analyze the restart soundness, write the testcontainers test, and draft this description.