Skip to content

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

Open

Description

@WorrierKhushal

What happened

In pkg/yurthub/storage/disk/storage.go, ReplaceComponentList() is responsible for atomically replacing the full set of cached objects for a given component/resource during a cloud-reconnect resync. It acquires a pending lock on the key prefix (via lockComponentKey()), writes all objects from the fresh LIST response to a staging area, then promotes them to the final cache directory.

During the resync window while ReplaceComponentList() holds the pending lock, any concurrent Update() or Create() calls for objects under the same key prefix (coming from concurrent watch events that arrived during the same reconnect window) hit lockKey(), detect the pending lock, and return storage.ErrStorageAccessConflict.

In pkg/yurthub/cachemanager/cache_manager.go, storeObjectWithKey() catches ErrStorageAccessConflict and — even after the fix in PR #2712 — only avoids updating the in-memory cache, but does NOT retry the disk write after the lock is released. Once ReplaceComponentList() completes and promotes its snapshot, those conflicting objects are permanently absent from disk with no mechanism to re-request or re-write them.

The consequence is that the final disk cache after a resync may be missing objects that arrived via watch between the LIST response and the completion of ReplaceComponentList(). On the next edge-autonomous period (cloud disconnect), YurtHub serves this incomplete snapshot to Kubelet.

What you expected to happen

Objects that arrive via watch during a ReplaceComponentList() resync window should either be included in the replacement snapshot, or be reliably retried for disk write after the lock is released. The disk cache should reflect a consistent state that includes both the LIST snapshot and any watch events received during the resync.

How to reproduce it (as minimally and precisely as possible)

  1. Run go test -race -v ./pkg/yurthub/cachemanager/...
  2. Set up a test where ReplaceComponentList() is artificially delayed (via a channel/sync mechanism in a fake storage wrapper) while a concurrent CacheResponse() watch event for a new object under the same prefix is injected.
  3. After both complete, read the object from disk cache and confirm it is absent — only the LIST snapshot objects are present.

Anything else we need to know?

  • Severity: High. This is a data-loss bug affecting edge autonomy correctness — the exact scenario OpenYurt is designed to protect. A disconnected edge node will serve Kubelet an incomplete/stale snapshot that silently omits objects that were legitimately created/updated just before the disconnect. The missing state is permanent on disk until the next full resync (i.e. next cloud reconnect + LIST), and does not self-heal between reconnects.
  • Context: This is structurally related to PR [BUG] Silent watch event drop during disk storage list-replacement causes permanent cache inconsistency between memory and disk #2712 (watch event drop during ReplaceComponentList) but affects a different code path — that fix prevented in-memory divergence; this gap means disk itself is also missing the object.

Environment

  • OpenYurt version: master branch
  • Kubernetes version: N/A (code-level defect)
  • OS: N/A
  • Kernel: N/A
  • Install tools: N/A

/kind bug

Activity

  1. WorrierKhushal commented on Aug 28, 2026

    @WorrierKhushal
    ContributorAuthor

    Hi maintainers, I've traced this issue and have a concrete fix plan ready.

    Root Cause

    ReplaceComponentList() holds a pending lock (lockComponentKey()) across its full disk I/O sequence. Concurrent watch events arriving during this window hit ErrStorageAccessConflict in Update()/Create() and are permanently dropped from disk — the #2712 fix correctly prevented in-memory divergence, but the disk write was never retried, leaving the on-disk snapshot silently incomplete after every resync.

    Proposed Approach

    After ReplaceComponentList() completes and releases its lock, any watch events that were rejected with ErrStorageAccessConflict during the locked window need to be durably written to disk.

    When storeObjectWithKey() catches ErrStorageAccessConflict, instead of returning silently, it enqueues the key + object into a small pending buffer owned by CacheManager. A goroutine (or the existing saveWatchObject retry path) drains this buffer after the lock releases, reusing the existing saveOneObject() write path so no new disk I/O pattern is introduced.

    Why this is the cleanest approach:

    • Non-blocking: Does not stall the watch-reading goroutine (no blocking retry in the hot path).
    • Code Reuse: Reuses saveOneObject() — the existing, already-tested single-object write path used throughout cache_manager.go.
    • Zero Interface Overhead: Does not require any interface changes to storage.Store.
    • Order Guarantee: Write ordering is preserved since the buffer is drained sequentially after the replace completes.

    Code Draft (pkg/yurthub/cachemanager/cache_manager.go)

    go

    // storeObjectWithKey() handling ErrStorageAccessConflict:
    case errors.Is(err, storage.ErrStorageAccessConflict):
        klog.V(2).Infof("queuing watch event for key(%s) for retry after replace completes", key.Key())
        cm.pendingWrites.enqueue(key, obj)
        return storage.ErrStorageAccessConflict
    
    // After ReplaceComponentList() completes (in saveListObject or equivalent):
    cm.pendingWrites.drain(func(key storage.Key, obj runtime.Object) {
        if err := cm.saveOneObject(ctx, info, key, obj); err != nil {
            klog.Errorf("failed to retry pending watch write for key(%s): %v", key.Key(), err)
        }
    }) 
    

    ###Call Site Audit
    storeObjectWithKey() is called from saveWatchObject() and saveOneObject() only (grep -rn "storeObjectWithKey" pkg/).

    ReplaceComponentList() is called from saveListObject() only (grep -rn "ReplaceComponentList" pkg/).

    No public interface changes made; no other callers affected.

    ###Testing Plan
    Add a deterministic test in cache_manager_test.go using a channel-controlled fake StorageWrapper (following the pattern of TestWatchDuringReplaceComponentListKeepsMemoryAndDiskConsistent added in #2712) to:

    Force a concurrent watch event during ReplaceComponentList()'s locked window.

    After both goroutines complete, read the object directly from the disk cache (not just in-memory cache) and assert its presence.

    This test will fail on master and pass with this fix.

    ###Verification Workflow
    go build ./pkg/yurthub/cachemanager/...
    go build ./pkg/yurthub/storage/disk/...
    go vet ./pkg/yurthub/cachemanager/...
    go test -v ./pkg/yurthub/cachemanager/...
    go test -race -v ./pkg/yurthub/cachemanager/...

    No exported signatures changed. No new interfaces introduced. Minimal, scoped change reusing existing write infrastructure.
    Would appreciate your feedback before opening the PR — happy to adjust if you see a simpler path!

  2. WorrierKhushal commented on Aug 29, 2026

    @WorrierKhushal
    ContributorAuthor

    Hi @zyjhtangtang @luc99hen @Fei-Guo maintainers,
    i am just opened the PR #2786 for the issues Silent object loss during disk cache ReplaceComponentList when concurrent writes arrive mid-resync in YurtHub
    if you have the time please review my this PR

  3. stale commented on Dec 4, 2026

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions