Close state storage in the UTXO and digest state property tests - #2460
Merged
kushti merged 1 commit intoAug 10, 2026
Merged
Conversation
kushti
approved these changes
Aug 10, 2026
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.
The leak
Every
createUtxoStateopens a fresh LevelDB under a new temp dir.ErgoState.closeStorage()exists, but the only callers are inErgoNodeViewHolder— no test has ever closed one. Measured on master, 40 calls in a loop:UtxoStateSpecificationandDigestStateSpecificationhave 14 properties between them doingforAll(boxesHolderGen), each opening a state per iteration at ScalaTest's defaultminSuccessful = 10. Nothing is released until the JVM exits.The effect
Peak open file descriptors while running just these two suites, sampled from
/proc/<pid>/fdevery 300ms:A 58% drop from 20 added lines. For scale, the default limit on the container I measured this on is 4096 — two suites out of a ~740-test job were sitting at 59% of it.
I ran into this the hard way: a loop calling the
UtxoStateSpecificationproperty body 500 times died at roughly 450 withjava.nio.file.FileSystemException: ... Too many open files.The change
us.closeStorage()at the end of eachforAll(boxesHolderGen)body, plusds.close()where the property also builds aDigestState. Nothing else.DigestStateSpecification'sreopenproperty already did exactly this — the convention existed, it just was not applied anywhere else.Derived states share the parent's
store, so one close per created store is enough and closing the original covers everythingapplyModifier/rollbackToreturned.testOnly ... UtxoStateSpecification ... DigestStateSpecification— 27 tests, green.Two honest notes
This may or may not fix the flaky CI.
Run node testsfails intermittently in exactly these two suites — a different one each time — withIllegalArgumentException: requirement failedduringforAll(boxesHolderGen)evaluation. Descriptor exhaustion would explain the "different suite each run" pattern, and it would explain why neither suite reproduces alone. But I could not reproduce the failure locally (300 generator runs and 500 full property runs, clean), so I am not claiming this is the cause. The leak is worth fixing on its own terms.closeStorage()logs. It doeslog.warn("Closing state's store."), meant for node shutdown, so this adds ~140 WARN lines to the node test log. If that is unwelcome I am happy to switch tous.store.close(), or to move the log to debug in a separate commit — your call.