Fix InputStream leak in RenewableTlsUtils.createSSLFactory#18483
Open
dkranchii wants to merge 1 commit into
Open
Fix InputStream leak in RenewableTlsUtils.createSSLFactory#18483dkranchii wants to merge 1 commit into
dkranchii wants to merge 1 commit into
Conversation
Use try-with-resources so key store and trust store streams are closed on the exception path, matching the sibling TlsUtils utilities.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18483 +/- ##
============================================
- Coverage 63.68% 63.66% -0.03%
- Complexity 1684 1685 +1
============================================
Files 3262 3265 +3
Lines 199835 199739 -96
Branches 31034 31011 -23
============================================
- Hits 127266 127161 -105
- Misses 62416 62440 +24
+ Partials 10153 10138 -15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
What
Switch the key store and trust store
InputStreams inRenewableTlsUtils.createSSLFactoryto try-with-resources.Why
The streams were closed only on the success path, after
SSLFactory.builder().build()returned. Any exception thrown in between — null trust-store password, malformed keystore, failure innl.altindag.ssl's builder, etc. — was caught and rewrapped asIllegalStateException, but the open stream was never closed. The leak is most likely to trigger during cert rotation (reloadSslFactoryretries 3x and the file watcher catches mid-write states), which compounds it on long-running broker/server/controller/minion processes.TlsUtils.createKeyManagerFactoryandTlsUtils.createTrustManagerFactoryin the same package already use this idiom, so the change also removes inconsistency.Safety
withIdentityMaterial(InputStream, char[], String)andwithTrustMaterial(InputStream, char[], String)consume the stream synchronously into aKeyStore; the stream is not retained forbuild(). Closing right after thewith...call is equivalent to the prior post-build()close on the success path.IllegalStateExceptionwrapping the cause).Test plan
./mvnw -pl pinot-common -am -Dtest=RenewableTlsUtilsTest -Dsurefire.failIfNoSpecifiedTests=false test./mvnw spotless:apply -pl pinot-common./mvnw checkstyle:check -pl pinot-common./mvnw license:check -pl pinot-common