Repository navigation
[api] Parse a new owner cache entry without holding its lock - #65302
Open
Christopher Plieger (cplieger) wants to merge 1 commit into
Open
Christopher Plieger (cplieger) wants to merge 1 commit into
Christopher Plieger (cplieger) wants to merge 1 commit into
Conversation
LoadAndAcquire still returns a live, unexpired entry under its lock. Otherwise it parses with no lock held, then stores the value and adds the owner under the entry's lock, so two loads that re-enter the cache for each other no longer wait on each other's lock. Concurrent loads of one key that find no live, unexpired entry may each parse it; the first value stored wins and a later parse is dropped. Tested with go vet and go test -race on internal/project and internal/api, npx hereby lint, npx hereby check:format and npx hereby test, all passing. TestOwnerCacheConcurrentlyLoadKeysThatLoadEachOther fails on main with its deadlock message and passes here. TestOwnerCacheConcurrentLoadsKeepFirstStoredValue fails on main after 10 seconds because the second load waits on the first parse's lock, fails on this change with every parse stored because the slower parse replaces the first value, and passes here.
5 of 6 tasks
This was referenced Nov 4, 2026
Open
2 of 7 tasks
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the OwnerCache locking change intended to prevent deadlocks during concurrent loads.
No open issues 🎉
What changed in this PR
Fixes #65300 by moving OwnerCache parsing outside entry locks, preventing concurrent API snapshot creation from deadlocking when projects enter a circular extends chain.
Changes:
- Preserves locked access to live, unexpired cache entries while parsing misses and expired entries without holding a lock.
- Allows concurrent parses while retaining the first stored value if it remains live and unexpired.
- Adds regression tests for recursive concurrent loads and first-stored-value behavior.
| File | Description |
|---|---|
tsc/internal/project/ownercache.go |
Moves parsing outside entry locks and rechecks the cache before storing. |
tsc/internal/project/ownercache_test.go |
Tests deadlock prevention and value retention during concurrent loads. |
Review effort: Balanced
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.
OwnerCache.LoadAndAcquireparses a new or expired entry while holding that entry's lock. In the extended config cache, the parse callsGetExtendedConfigfor each config the entry extends, which callsLoadAndAcquireagain. Two snapshots that enter a circularextendschain at different points then each hold one entry and wait for the other's, and neithercreateSnapshotreturns.Impact: an analyzer that opens a repository's projects concurrently on the API waits forever, with no error, on a repository where two configs extend into one circular
extendschain at different points.LoadAndAcquirestill returns a live, unexpired entry under its lock. Otherwise it now parses with no lock held, then stores the value and adds the owner under the entry's lock. The one behavior change is that concurrent loads of one config that find no live, unexpired entry may each parse it. The first value stored wins, and a later parse is dropped when it finds a live, unexpired entry. The CLI's own extended config cache has the same pattern, reported in #64833, and #64835 fixes it the same way.TestOwnerCacheConcurrentlyLoadKeysThatLoadEachOtherloadsaandbon two goroutines with a parse that waits until both loads have started and then loads the other key, as two configs of one cycle do. Onmainthe two loads never return, and the test fails after 10 seconds with a deadlock message in 10 of 10 runs, plain and with-race. It drives the cache directly because a test of two concurrent snapshots hangs onmainin only about 6 of 10 runs.TestOwnerCacheConcurrentLoadsKeepFirstStoredValuestarts a slow parse ofa, loadsaagain with a different value while that parse waits, and then lets it finish. All three loads must return the value of the load that stored first. Onmainthe second load waits on the first parse's lock, and the test fails after 10 seconds in 10 of 10 runs. Becausemainstops there, I checked the case it guards on this change with every parse stored, where it fails in 10 of 10 runs because the slow parse replaces the first value. With atscbuilt from this branch, the reproduction in the issue returns in all 100 rounds in 3 of 3 runs.This replaces part of #64825. I met it while building deadset-ts, the TypeScript analyzer of deadset, on the TypeScript 7 API.
An AI coding agent wrote this patch. I have read, built and tested it and will handle the review.
Backlogmilestone (required)mainbranchnpx hereby testnpx hereby lintnpx hereby check:formatFixes #65300