fix(cache,da): drop finalized snapshot entries on restore and drain DA subscription channel#3385
Open
tac0turtle wants to merge 2 commits into
Open
fix(cache,da): drop finalized snapshot entries on restore and drain DA subscription channel#3385tac0turtle wants to merge 2 commits into
tac0turtle wants to merge 2 commits into
Conversation
…A subscription channel Two memory fixes for long-running nodes: Cache restore: the DA-inclusion snapshot is only written on graceful shutdown, so after a crash (e.g. OOM kill) the restored snapshot can contain heights already below the persisted DA-included watermark. The inclusion loop never evicts below its watermark, so those placeholder entries leaked for the process lifetime and were re-persisted on every subsequent save, growing the snapshot monotonically across crash/restart cycles. RestoreFromStore now skips entries at or below the persisted DAIncludedHeight; skipped entries still seed maxDAHeight so DaHeight() is unchanged. DA subscription: the Subscribe wrapper goroutine exited on ctx cancellation without draining the underlying jsonrpc channel, leaving the go-jsonrpc delivery goroutine blocked on send — it never observed the cancellation and never closed its channel, leaking one goroutine per watchdog reconnect. The wrapper now drains the raw channel on exit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
|
The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3385 +/- ##
==========================================
- Coverage 62.33% 62.32% -0.01%
==========================================
Files 120 120
Lines 13425 13433 +8
==========================================
+ Hits 8368 8372 +4
- Misses 4118 4120 +2
- Partials 939 941 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Overview
Two memory fixes for long-running nodes, found while investigating a user report of sustained memory growth (+201 MiB/min) and OOM kills on syncing nodes.
1. Cache restore leaks stale placeholders across crash/restart cycles
The DA-inclusion snapshot is only persisted on graceful shutdown (
Components.Stop). After a crash (e.g. OOM kill, SIGKILL), the node restores a snapshot from the last graceful shutdown, which can contain heights already at or below the persistedDAIncludedHeightwatermark. Since:DeleteHeightfor heights it advances through, andIsHeightDAIncludedshort-circuitstruebelow the watermark so those entries are never consulted,restored placeholders below the watermark were never evicted, and were re-persisted on the next graceful save — so the snapshot grew monotonically across crash/restart cycles.
Cache.RestoreFromStorenow takes the finalized height and skips entries at or below it. Skipped entries still contribute tomaxDAHeight, soDaHeight()semantics are unchanged.manager.RestoreFromStorereadsDAIncludedHeightKeyand passes it through; a read error falls back to unfiltered restore instead of failing startup.The pre-existing comment in
TestManager_SaveAndRestoreFromStorealready described this as the intended behavior ("The cache entry is not restored — this is correct and intentional") — the code just didn't do it. It now does, and the test asserts it.2. DA subscription goroutine leak on reconnect
The
client.Subscribewrapper goroutine exited on ctx cancellation without draining the underlying jsonrpc channel. The go-jsonrpc delivery goroutine blocked on send into that channel never observed the cancellation and never closed its channel — leaking one goroutine per watchdog reconnect (observed in the field asSubscribe.func1goroutines doubling). The wrapper now drains the raw channel on exit, matching what its own doc comment previously required of callers.Testing
TestCache_RestoreFromStore_SkipsFinalizedEntriescovering partial and fully-stale snapshotsTestManager_SaveAndRestoreFromStorenow asserts finalized heights are not restoredgo test ./block/...,go vet,golangci-lintall cleanNote: this does not address the primary OOM driver from the same investigation (unbounded
pendingEventsbuffering when DA catchup outpaces execution) — that needs a separate backpressure change.🤖 Generated with Claude Code