Skip to content

fix: retry disk writes dropped during ReplaceComponentList resync window to prevent silent object loss in edge cache - #2786

Open
WorrierKhushal wants to merge 2 commits into
openyurtio:masterfrom
WorrierKhushal:fix/2780-disk-cache-pending-write-loss
Open

fix: retry disk writes dropped during ReplaceComponentList resync window to prevent silent object loss in edge cache#2786
WorrierKhushal wants to merge 2 commits into
openyurtio:masterfrom
WorrierKhushal:fix/2780-disk-cache-pending-write-loss

Conversation

@WorrierKhushal

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

During a cloud-reconnect resync, ReplaceComponentList() in
pkg/yurthub/storage/disk/storage.go holds a pending lock
(lockComponentKey()) across its full disk I/O sequence. Any concurrent
watch events arriving for objects under the same key prefix during this
window hit ErrStorageAccessConflict in Update()/Create() and are
permanently dropped from disk.

PR #2712 correctly fixed the in-memory divergence half of this problem —
it prevented the in-memory cache from getting ahead of disk when a
conflict occurs. But the disk write itself was still never retried, so
the on-disk snapshot after every resync silently omits any objects that
arrived via watch during the replace window.

On the next edge-autonomous period (cloud disconnect), YurtHub serves
this incomplete snapshot to Kubelet — missing objects that were
legitimately created or updated just before the disconnect. The missing
state is permanent on disk until the next full resync.

This PR fixes the second half: when storeObjectWithKey() catches
ErrStorageAccessConflict, it now enqueues the key+object into a small
pendingWrites buffer on CacheManager. After ReplaceComponentList()
completes and releases its lock, saveListObject() drains this buffer
using the existing saveOneObject() write path — reusing already-tested
infrastructure, no new disk I/O patterns, no storage.Store interface
changes.

Added a deterministic regression test that forces the exact conflict
window using a channel-controlled fake StorageWrapper (same pattern
as the test added for #2712), confirms the object is absent from disk
before the fix, and present after.

Which issue(s) this PR fixes:

Fixes #2780

Special notes for your reviewer:

Does this PR introduce a user-facing change?

fix(yurthub): prevent silent loss of watch-event objects from disk cache 
during cloud-reconnect resync window; objects that arrived via watch 
while ReplaceComponentList held its lock are now reliably written to disk 
after the replace completes.

other Note

…ade responses

- Replace pooled bufio reader with unpooled bufio.NewReader in getResponse to prevent premature recycling before serveUpgradeRequest writes the response body.
- Add TestServeUpgradeRequest_ConcurrentRace to validate thread safety under concurrent requests.
@WorrierKhushal
WorrierKhushal requested a review from a team as a code owner August 29, 2026 09:11
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.19048% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.29%. Comparing base (ddf22f7) to head (b95999a).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
pkg/yurthub/cachemanager/cache_manager.go 75.00% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2786      +/-   ##
==========================================
+ Coverage   46.20%   46.29%   +0.09%     
==========================================
  Files         405      405              
  Lines       27540    27583      +43     
==========================================
+ Hits        12724    12769      +45     
+ Misses      13649    13636      -13     
- Partials     1167     1178      +11     
Flag Coverage Δ
unittests 46.29% <76.19%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Silent object loss during disk cache ReplaceComponentList when concurrent writes arrive mid-resync in YurtHub

1 participant