hud/server: make apiserver config registration atomic - #6815
Open
prajwalshah19 wants to merge 1 commit into
Open
hud/server: make apiserver config registration atomic#6815prajwalshah19 wants to merge 1 commit into
prajwalshah19 wants to merge 1 commit into
Conversation
addToAPIServerConfig and removeFromAPIServerConfig read the shared config file under a read lock, released it, mutated an in-memory copy, and wrote the full snapshot back under a separate write lock. Two Tilt processes could read the same base snapshot and the later writer would discard the earlier writer's registration or removal, leaving clients failing with "No tilt apiserver found: <name>" while the server was still running. Hold the exclusive file lock across the entire read-modify-write so concurrent processes serialize on the whole transaction. Signed-off-by: prajwalshah19 <70662078+prajwalshah19@users.noreply.github.com>
prajwalshah19
force-pushed
the
fix/apiserver-config-lost-update
branch
from
August 2, 2026 17:38
dc4fa68 to
e3db3e3
Compare
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.
Fixes #6814.
addToAPIServerConfigandremoveFromAPIServerConfigread the shared config under a read lock, released it, mutated an in-memory copy, and later wrote the full snapshot back under a separate write lock. The write lock serializes writers but doesn't protect the whole transaction, so two Tilt processes can read the same base snapshot and the later writer discards the earlier one's registration or removal.The result is a CLI command failing with
No tilt apiserver found: tilt-<port>against a server that is still running and healthy — the entry was simply dropped from the config by an unrelated Tilt process.This holds the exclusive lock across the entire read-modify-write in both functions, so concurrent processes serialize on the full transaction.
modifyConfigwas only used by these two callers and is inlined into them;ValidateAPIServerNamenow runs before the read, so an invalid name no longer takes the lock or touches the file.No deadlock risk from the nested
clientcmd.ModifyConfigcall:internal/filelock'sinit()setsclientcmd.UseModifyConfigLock = false, soModifyConfigdoesn't take a lock of its own.Testing
TestConcurrentAPIServerConfigUpdatesregisters and then deregisters 8 controllers concurrently against one config file. It fails on master — an entry survives after every removal, the lost-update — and passes with the fix. Clean under-race -count=10.Also run:
make shorttest(full suite; the only failures are the pre-existingTestKustomizeFlags/TestKustomizeBin, which fail identically on unmodifiedmasterbecausekustomizeisn't on my PATH),go vet,goimports -local github.com/tilt-dev, andgolangci-lint(0 issues).Notes for reviewers
tiltbinary alongside a fixed one can still clobber the config.LockFileExexclusive per handle) but I haven't run it there.