Simplify waitForCloseablesToClose() to focus on waiting semantics#843
Open
peter-lawrey wants to merge 2 commits into
Open
Simplify waitForCloseablesToClose() to focus on waiting semantics#843peter-lawrey wants to merge 2 commits into
peter-lawrey wants to merge 2 commits into
Conversation
|
tgd
reviewed
Apr 28, 2026
tgd
requested changes
Apr 28, 2026
tgd
approved these changes
Jun 2, 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.



Refactor
CloseableUtils.waitForCloseablesToClose(long)so its behaviour matches its name and return type more clearly: it now only waits for tracked closeables to enter the closing state within the given timeout and returnstrueorfalseaccordingly.Motivation
waitForCloseablesToClose(long)previously mixed two responsibilities:That made the method harder to read and blurred the distinction between it and
assertCloseablesClosed(), which is the method intended for strict validation and failure reporting.This change makes the contract clearer:
waitForCloseablesToClose(long)is a polling/wait helperassertCloseablesClosed()remains the diagnostic/assertion pathChange
The method has been simplified to:
invoke pending cleanup work up front
CleaningThreadLocal.cleanupNonCleaningThreads()BackgroundResourceReleaser.releasePendingResources()check whether all tracked
ManagedCloseableinstances are already closingreturn
trueonce they arereturn
falseif the timeout expirespause briefly between checks rather than re-running assertion-oriented logic
The call in
finalize()has also been updated to use the local method directly, improving readability.What was removed
The previous implementation included behaviour that was more appropriate for assertion/debug flows, including:
AbstractCloseablethrowExceptionIfNotReleased()onReferenceCountedTracerIllegalStateExceptionThat logic obscured the purpose of the method and overlapped with
assertCloseablesClosed().Behavioural intent
This is primarily a clarity and responsibility-separation change:
waitForCloseablesToClose(long)now has straightforward wait semanticsassertCloseablesClosed()remains the place for stronger verification and failure signallingBenefits
Notes
A
@seelink has been added in both directions to make the relationship between the two methods explicit.