Skip to content

Fix FileInputStream resource leaks in RabbitMQ and MQTT SSL configurations#1838

Open
Sunny-Hasho wants to merge 1 commit into
wso2:masterfrom
Sunny-Hasho:fix-inbound-endpoints-ssl-leaks
Open

Fix FileInputStream resource leaks in RabbitMQ and MQTT SSL configurations#1838
Sunny-Hasho wants to merge 1 commit into
wso2:masterfrom
Sunny-Hasho:fix-inbound-endpoints-ssl-leaks

Conversation

@Sunny-Hasho

Copy link
Copy Markdown

Purpose

Fix file descriptor/resource leaks caused by unclosed FileInputStream objects inside RabbitMQ and MQTT inbound endpoint configurations.

Goals

Ensure all file input streams opened for loading SSL KeyStore and TrustStore files are properly closed after usage.

Approach

Refactored the SSL KeyStore and TrustStore loading logic in RabbitMQConnectionFactory.java and MqttConnectionFactory.java to use the standard try-with-resources statement. This is consistent with the resource handling patterns already used in other parts of this module (e.g., SSLHandlerFactory.java).

User stories

N/A

Release note

Fixed a file descriptor resource leak in RabbitMQ and MQTT inbound endpoint SSL configurations.

Documentation

N/A (No documentation impact as this is an internal resource management bug fix).

Automation tests

  • Unit tests run locally. No changes in public method signatures or behaviors.

Security checks

@Sunny-Hasho
Sunny-Hasho requested a review from arunans23 as a code owner July 7, 2026 17:54
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 20d6c204-0ce7-4ffa-91ab-69a67350085a

📥 Commits

Reviewing files that changed from the base of the PR and between 77b3ee1 and 46015a7.

📒 Files selected for processing (2)
  • components/inbound-endpoints/org.wso2.carbon.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/mqtt/MqttConnectionFactory.java
  • components/inbound-endpoints/org.wso2.carbon.inbound.endpoint/src/main/java/org/wso2/carbon/inbound/endpoint/protocol/rabbitmq/RabbitMQConnectionFactory.java

📝 Walkthrough

Updated RabbitMQ and MQTT inbound endpoint SSL setup to use try-with-resources when loading keystore and truststore files. This ensures the input streams are closed properly after use while leaving the existing connection and SSL initialization flow unchanged.

No public API changes were introduced.

Walkthrough

This change modifies keystore and truststore file loading in MqttConnectionFactory and RabbitMQConnectionFactory to use try-with-resources FileInputStream blocks instead of passing inline FileInputStream instances directly to KeyStore.load(...). The overall SSL initialization flow, including key/trust manager factory creation and SSLContext setup, remains unchanged in both classes.

Changes

Cohort / File Change Summary
MqttConnectionFactory.java Keystore/truststore streams in getSocketFactory wrapped in try-with-resources
RabbitMQConnectionFactory.java Keystore/truststore streams in setSSL wrapped in try-with-resources

Related issues: None referenced in the provided information.

Related PRs: None referenced in the provided information.

Suggested labels: bug, dependencies

Suggested reviewers: None specified.

Poem
A rabbit hopped by streams once left ajar,
Now closed with care, no matter how far.
MQTT and RabbitMQ, tidy at last,
Resources released as each block has passed.
A small fix indeed, but solid and neat. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main fix: closing FileInputStream leaks in RabbitMQ and MQTT SSL handling.
Description check ✅ Passed The description covers Purpose, Goals, Approach, Release note, tests, and security checks; several optional template sections are omitted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant