Repository navigation
Utility for detection of resource leaks - #4324
Conversation
PR SummaryMedium Risk Overview That pattern is wired through litt iterators/keymaps, pebbledb batches/DB/iterators/MVCC, view manager views and tracked iterators, flatkv (exporters, state views, atomic store views), hashvault, state WAL, giga StateDB, EVM SS, and staged snapshot types—replacing ad-hoc
Smaller fixes: Reviewed by Cursor Bugbot for commit 5945a33. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
There was a problem hiding this comment.
This PR adds a runtime.SetFinalizer-based leak detector and fixes a number of real leaks in production code and tests. I found no merge blockers, but there are three problems to address: finalizers on objects in reference cycles (they are never collected), a missing KeepAlive in the view-release path that can race, and finalizers added to hot-path iterators and batches.
Findings: 0 blocking | 5 non-blocking | 3 posted inline
Blockers
- None at the file/PR level.
Non-blocking
- [suggestion]
sei-db/common/utils/must_close.gohas no unit tests. Add tests that cover the leak-detected path, the path where an object was closed properly and nothing fires, and theMustClosewrapper. Because the utility depends on GC timing, it also needs a documented pattern such asruntime.GC()plus a polling loop so tests can check it deterministically. - [suggestion] In a test binary the finalizer panics on the shared finalizer goroutine. That crashes the whole package's test process at a point GC decides, so the failure is reported under whatever test happens to be running, not the one that leaked the object. Consider recording leaks and failing from a
TestMain/t.Cleanuphook, with a forced GC, so failures are deterministic and credited to the right test. - 3 suggestion(s)/nit(s) flagged inline on specific lines.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fd61f1b. Configure here.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4324 +/- ##
==========================================
- Coverage 67.70% 66.99% -0.72%
==========================================
Files 2168 2133 -35
Lines 168283 162448 -5835
==========================================
- Hits 113938 108824 -5114
+ Misses 54336 53614 -722
- Partials 9 10 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
The RocksDB job now runs against Ubuntu's librocksdb-dev package, which is built with assertions enabled. TestDatabasePrune left an iterator open when its deferred Close ran, and the column family that iterator still referenced tripped the `last_ref` assertion in ~ColumnFamilySet, aborting the whole mvcc test binary. main closes the iterator on the same line, added there by #4324. Co-authored-by: Cursor <cursoragent@cursor.com>

Creates a new utility for detecting and recovering from resource leaks.
Simply register an object that must be closed with this method. This should be done in constructors.
If the object becomes GC eligible without being properly closed, then the following happens:
Using this utility, I detected and fixed several potential production leaks, as well as a dozen or so leaks in unit tests.