Skip to content

fix(cache,da): drop finalized snapshot entries on restore and drain DA subscription channel#3385

Open
tac0turtle wants to merge 2 commits into
mainfrom
marko/cache-restore-filter-sub-drain
Open

fix(cache,da): drop finalized snapshot entries on restore and drain DA subscription channel#3385
tac0turtle wants to merge 2 commits into
mainfrom
marko/cache-restore-filter-sub-drain

Conversation

@tac0turtle

Copy link
Copy Markdown
Contributor

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 persisted DAIncludedHeight watermark. Since:

  • the inclusion loop only calls DeleteHeight for heights it advances through, and
  • IsHeightDAIncluded short-circuits true below 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.RestoreFromStore now takes the finalized height and skips entries at or below it. Skipped entries still contribute to maxDAHeight, so DaHeight() semantics are unchanged. manager.RestoreFromStore reads DAIncludedHeightKey and passes it through; a read error falls back to unfiltered restore instead of failing startup.

The pre-existing comment in TestManager_SaveAndRestoreFromStore already 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.Subscribe wrapper 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 as Subscribe.func1 goroutines doubling). The wrapper now drains the raw channel on exit, matching what its own doc comment previously required of callers.

Testing

  • New TestCache_RestoreFromStore_SkipsFinalizedEntries covering partial and fully-stale snapshots
  • TestManager_SaveAndRestoreFromStore now asserts finalized heights are not restored
  • go test ./block/..., go vet, golangci-lint all clean

Note: this does not address the primary OOM driver from the same investigation (unbounded pendingEvents buffering when DA catchup outpaces execution) — that needs a separate backpressure change.

🤖 Generated with Claude Code

…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>
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch marko/cache-restore-filter-sub-drain

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed⏩ skippedJul 15, 2026, 1:41 PM

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.32%. Comparing base (e437a62) to head (b769abd).

Files with missing lines Patch % Lines
block/internal/cache/manager.go 16.66% 2 Missing and 3 partials ⚠️
block/internal/da/client.go 50.00% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
combined 62.32% <50.00%> (-0.01%) ⬇️

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.

1 participant