Repository navigation
SOLR-18578: Close AutoCloseable-only objects in ObjectReleaseTracker.tryClose() - #5213
Open
nick-boss-tech wants to merge 1 commit into
Open
nick-boss-tech wants to merge 1 commit into
nick-boss-tech wants to merge 1 commit into
Conversation
nick-boss-tech
marked this pull request as ready for review
October 23, 2026 19:34
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.
🤖 AI text below 🤖 (posted on behalf of Nick Shanin)
https://issues.apache.org/jira/browse/SOLR-18578
What happens today
ObjectReleaseTracker.tryClose(), the test framework's failure cleanup, never closes tracked objects that implement onlyAutoCloseable.tryClose()handles two kinds of tracked objects:CloseableandExecutorService.SolrTestCasecalls it after a test class fails, so anything it skips stays open during failure recovery. Three tracked types implement onlyAutoCloseable:SolrMetricsContext, which tracks itself and whoseclose()closes its registered resources;ZkCollectionTerms; andZkShardTerms. A leaked metrics context therefore survives the cleanup pass with its registered resources open. SOLR-17857 added the tracker registration forSolrMetricsContext; the two-branch shape oftryClose()dates to SOLR-15550 and was not widened then.Change
tryClose()gains a finalAutoCloseablebranch; theCloseableandExecutorServicebranches are unchanged.The branch order preserves the executor special case, which shuts down through
ExecutorUtil.shutdownAndAwaitTermination, and a close failure is logged while cleanup continues, matching the existing branches. The new branch is six lines:ObjectReleaseTracker.javaat the head. Before the branch was added, every tracked AutoCloseable-only type was checked for close safety:SolrMetricsContext.close()releases its own tracker entry and closes registered resources quietly;ZkCollectionTerms.close()closes the contained shard terms under its lock;ZkShardTerms.close()is repeat-safe, which matters because a collection close can close a shard term the tracker iteration later reaches on its own.TestObjectReleaseTrackergains five tests: a minimal AutoCloseable-only tracked object is closed exactly once and untracked; cleanup continues after oneclose()throws; a realSolrMetricsContextwith a registered resource is closed; a tracked parent/child pair ends in the intended state when both are in the tracker; the executor branch still handles anExecutorService. Each new test clears the global tracker in afinallyblock.Proof
At head
35faf539e94, with seed3B1F3E98A7C2D144:TestObjectReleaseTrackerruns 10 tests with 0 failures, 0 errors, 0 skipped (the class had 5 tests before this change). With onlyObjectReleaseTracker.javarestored to its base version and this head's tests kept, four of the five new tests fail, each because the tracked object's close counter stays at 0:testTryCloseAutoCloseable,testTryCloseContinuesAfterAutoCloseableFailure,testTryCloseSolrMetricsContextClosesRegisteredResourcesandtestTryCloseNestedAutoCloseables. The fifth new test passes on both versions, as it should: it pins the pre-existing executor branch. Tidy passes on the changed files.:solr:core:check -x testand:solr:solrj:check -x testpass with-Pvalidation.errorprone=true. No full module test suite was run.Limits
ObjectReleaseTrackerchanges.Checklist
changelogentry to the changelog fragment directory.🤖 AI footer 🤖 This pull request description was written by an AI assistant on behalf of Nick Shanin, who directed the work and takes responsibility for the contribution.