Fixes #27091 : Fix resource leaks in SamlSettingsHolder, SamlValidator, and IndexResource#27092
Conversation
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
openmetadata-service/src/main/java/org/openmetadata/service/resources/system/IndexResource.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR addresses resource-leak issues in the backend (openmetadata-service) by ensuring streams and network connections are properly closed in SAML-related code and the root index HTML resource handler.
Changes:
- Use try-with-resources to close the keystore
FileInputStreaminSamlSettingsHolder. - Ensure
HttpURLConnectionis always disconnected and related streams/deflaters are closed inSamlValidator. - Close classpath resource streams in
IndexResourceand add explicit “resource missing” errors instead of NPEs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
openmetadata-service/src/main/java/org/openmetadata/service/security/saml/SamlSettingsHolder.java |
Wraps keystore file loading in try-with-resources to avoid FD leaks. |
openmetadata-service/src/main/java/org/openmetadata/service/security/auth/validator/SamlValidator.java |
Adds connection disconnect + stream/deflater lifecycle management during IdP connectivity validation and request generation. |
openmetadata-service/src/main/java/org/openmetadata/service/resources/system/IndexResource.java |
Closes /assets/index.html classpath stream and throws clear errors when missing/unreadable. |
...ta-service/src/main/java/org/openmetadata/service/security/auth/validator/SamlValidator.java
Show resolved
Hide resolved
openmetadata-service/src/main/java/org/openmetadata/service/resources/system/IndexResource.java
Outdated
Show resolved
Hide resolved
openmetadata-service/src/main/java/org/openmetadata/service/resources/system/IndexResource.java
Outdated
Show resolved
Hide resolved
…ource - SamlSettingsHolder: Wrap FileInputStream in try-with-resources in initDefaultSettings() to prevent file descriptor leak - SamlValidator: Add try-finally with conn.disconnect() in validateIdpConnectivity() to prevent TCP socket leak; close InputStream in readResponseSnippet(); close DeflaterOutputStream and Deflater in createTestSamlRequest() - IndexResource: Wrap InputStream/BufferedReader in try-with-resources in both constructor and getIndexFile(); add null check for missing classpath resource
466b631 to
dee291d
Compare
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
...ta-service/src/main/java/org/openmetadata/service/security/auth/validator/SamlValidator.java
Show resolved
Hide resolved
Code Review ✅ Approved 2 resolved / 2 findingsFixes resource leaks in SamlSettingsHolder, SamlValidator, and IndexResource by adding proper try-with-resources blocks and ensuring BufferedReader cleanup. All issues resolved with no remaining findings. ✅ 2 resolved✅ Bug:
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Gitar
Fix resource leaks in SamlSettingsHolder, SamlValidator, and IndexResource
Fixes #27091
Describe your changes
Close three resource leak bugs across
openmetadata-servicewhere streams and connections were opened but never closed, leaking file descriptors and TCP sockets.SamlSettingsHolder — FileInputStream never closed
SamlSettingsHolder.initDefaultSettings()created aFileInputStreaminline insidekeyStore.load(new FileInputStream(...)). Since the stream reference was never assigned to a variable, it could never be closed — leaking a file descriptor on every SAML settings load.Fix: Wrap in try-with-resources:
SamlValidator — HttpURLConnection never disconnected
SamlValidator.validateIdpConnectivity()opened anHttpURLConnectionto test the IdP SSO URL but never calledconn.disconnect()in any code path, leaking a TCP socket per validation. Additionally:readResponseSnippet()read from the connection's error/input stream without closing itcreateTestSamlRequest()created aDeflaterOutputStreamandDeflaterwithout closing themFix: Wrapped the connection usage in try-finally with
conn.disconnect(), wrappedreadResponseSnippet's stream in try-with-resources, and wrapped the deflater streams in try-with-resources withdeflater.end()in finally.IndexResource — InputStream and BufferedReader never closed
Both the constructor and
getIndexFile()opened anInputStreamviagetResourceAsStream()and wrapped it in aBufferedReader, but neither was ever closed. Additionally, no null check existed — a missing resource would cause an unhelpful NPE.Fix: Wrapped both methods in try-with-resources with null checks that throw
IllegalStateExceptionwith clear context.This continues the resource leak cleanup pattern from PR #27063, which fixed identical
InputStreamleaks inSchemaFieldExtractor.Type of change
Checklist
mvn spotless:checkpasses)