Repository navigation
fix(cache): make ICacheStore release lifecycle atomic - #1731
Closed
xiaoyang-hhh wants to merge 1 commit into
Closed
xiaoyang-hhh wants to merge 1 commit into
xiaoyang-hhh wants to merge 1 commit into
Conversation
ICacheStore::release() held mt_ -- a photon::spinlock, so a pure busy-wait that never yields -- across pool_->store_release(). That call ends in ExpireContainerBase::expire(), whose delete_all() destroys other stores: ~FileCacheStore closes files and takes the pool's m_lock_, so it can block far longer than the store cache TTL. Once the deadline passes another thread's expire() legitimately frees this store, and the original releaser then unwinds out of SCOPED_LOCK(mt_) and writes one byte to freed memory in spinlock::unlock(). The same window is worse than a stray write. The object is destroyed while mt_ is still held and its destructor never unlocks it, so any thread that later reaches release() -- or tryget_size(), which shares mt_ -- spins on that lock forever. Observed live under a 4G disk cache: 15 threads pegged in spinlock::lock(), 420% CPU, 75 FUSE handles stuck, no progress for 23 hours. The unfixed build hung after 6.5h; the fixed one ran 25h with 4.2x the store-event volume and no report. Replace the mt_-protected lifecycle with an atomic detached_ state. The unique detacher removes the store from ObjectCache before dropping its own reference, and the final reference decrement uses acq_rel. Attached stores return their cache-held reference to ObjectCache; detached stores are deleted by their last external reference. Open handles therefore stay alive across detach and each store is destroyed exactly once without running blocking pool operations under mt_. Drop the unused need_detach_ flag. Keep the deterministic release_detach_vs_same_vcpu_reader_no_hang regression test, which reproduces the same-vCPU spinlock starvation through the real FileCachePool/FileCacheStore stack.
xiaoyang-hhh
marked this pull request as draft
November 6, 2026 09:03
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.
Summary
Tests
CachePool.concurrent_open_release_stress: 50 consecutive runs passedCachePool.release_detach_vs_same_vcpu_reader_no_hang: 10 consecutive runs passedcache_test: 24/24 passed