Skip to content

fix: pruning goroutine lifecycle management to prevent nil pointer on Close#2800

Open
blindchaser wants to merge 2 commits intomainfrom
yiren/fix-prune
Open

fix: pruning goroutine lifecycle management to prevent nil pointer on Close#2800
blindchaser wants to merge 2 commits intomainfrom
yiren/fix-prune

Conversation

@blindchaser
Copy link
Contributor

Describe your changes and provide context

  • Lifecycle management: Wrap StateStore with PrunableStateStore that stops the pruning goroutine before closing the underlying database
  • Remove duplicate Close: Remove redundant stateStore.Close() from HandleClose() since cms.Close() already handles it
  • Defensive checks: Add nil checks in Prune() methods for pebbledb/rocksdb as an additional safety layer
  • Idempotency: Use sync.Once to ensure Start/Stop/Close operations are safe to call multiple times

Testing performed to validate your change

@github-actions
Copy link

github-actions bot commented Feb 4, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedFeb 4, 2026, 7:07 PM

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 77.08333% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.65%. Comparing base (fe44b5d) to head (ddd89d9).

Files with missing lines Patch % Lines
sei-db/state_db/ss/pruning/manager.go 79.41% 5 Missing and 2 partials ⚠️
sei-db/db_engine/pebbledb/mvcc/db.go 0.00% 1 Missing and 1 partial ⚠️
sei-db/db_engine/rocksdb/mvcc/db.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2800      +/-   ##
==========================================
+ Coverage   46.94%   56.65%   +9.70%     
==========================================
  Files        1965     2031      +66     
  Lines      160525   165884    +5359     
==========================================
+ Hits        75363    93980   +18617     
+ Misses      78637    63666   -14971     
- Partials     6525     8238    +1713     
Flag Coverage Δ
sei-chain 41.51% <80.43%> (-0.01%) ⬇️
sei-cosmos 48.13% <ø> (+<0.01%) ⬆️
sei-db 68.42% <0.00%> (-0.31%) ⬇️
sei-tendermint 58.05% <ø> (?)

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

Files with missing lines Coverage Δ
app/app.go 71.46% <ø> (+0.21%) ⬆️
sei-db/state_db/ss/store.go 53.22% <100.00%> (+7.94%) ⬆️
sei-db/db_engine/pebbledb/mvcc/db.go 63.85% <0.00%> (-0.23%) ⬇️
sei-db/db_engine/rocksdb/mvcc/db.go 57.31% <0.00%> (-0.47%) ⬇️
sei-db/state_db/ss/pruning/manager.go 83.72% <79.41%> (+42.81%) ⬆️

... and 320 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

default:
}

pruneStartTime := time.Now()

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
}
m.startOnce.Do(func() {
m.wg.Add(1)
go m.pruneLoop()

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
time.Sleep(time.Duration(m.pruneInterval+randomDelay) * time.Second)
// Generate a random percentage (between 0% and 100%) of the fixed interval as a delay
randomPercentage := rand.Float64()
randomDelay := int64(float64(m.pruneInterval) * randomPercentage)

Check notice

Code scanning / CodeQL

Floating point arithmetic Note

Floating point arithmetic operations are not associative and a possible source of non-determinism
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant