Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the xcache live cache implementation to execute the OnSwap callback asynchronously in a separate goroutine, preventing potential stalls in the periodic refresh loop. The associated unit tests have been updated to use assert.Eventually to account for this change. Additionally, the StopAutoRefresh methods in DeviceFlowProvider and TokenProvider now utilize a 5-second timeout context during executor shutdown to prevent indefinite blocking. I have no feedback to provide as there were no review comments to evaluate.
Greptile SummaryThis PR fixes a cache-refresh issue by running the
Confidence Score: 5/5Safe to merge — all changes are additive logging, a bounded shutdown timeout, and a test race fix. All four files contain narrow, well-scoped changes: two providers gain a 5-second shutdown timeout that prevents the worker goroutine from blocking indefinitely, the cache gets observability log lines with no logic change, and the test correctly sequences the atomic increment after the plain writes to eliminate the data race from the prior review. No existing behavior is altered in a way that could regress. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant W as Worker goroutine
participant LI as loadInternal
participant OS as onSwap callback
participant SAR as StopAutoRefresh
W->>LI: doRefresh(ctx, force)
LI->>LI: "swap c.data & c.lastUpdate"
LI->>OS: log.Debug "onSwap starting"
LI->>OS: c.onSwap(old, newData)
OS->>SAR: exec.Shutdown(ctx 5s timeout)
SAR-->>OS: shutdown complete / timeout
OS-->>LI: return
LI->>LI: log.Debug "onSwap completed"
LI->>LI: log.Info "cache refreshed"
LI-->>W: return err
Reviews (2): Last reviewed commit: "fix: cache not refresh in some cache" | Re-trigger Greptile |
|
|
||
| c.onSwap(old, newData) | ||
| }() | ||
| log.Debug(ctx, "live cache onSwap completed", log.String("name", c.name)) |
There was a problem hiding this comment.
🟡 "onSwap completed" debug log emitted even when onSwap panicked
If c.onSwap(old, newData) panics, the deferred recover() inside the IIFE catches it and logs an error at line 238. However, because the panic is recovered, the IIFE returns normally, and execution continues to line 246 which unconditionally logs "live cache onSwap completed". This produces a misleading log sequence: first "onSwap callback panicked" (Error), then "onSwap completed" (Debug), falsely indicating success after a failure. For operational debugging, this can mask real issues.
| log.Debug(ctx, "live cache onSwap completed", log.String("name", c.name)) | |
| log.Debug(ctx, "live cache onSwap finished", log.String("name", c.name)) |
Was this helpful? React with 👍 or 👎 to provide feedback.
(cherry picked from commit 57ccc13)
Uh oh!
There was an error while loading. Please reload this page.