Skip to content

Fix BufferedReader resource leak in InputStreamConsumer#18469

Merged
danny0405 merged 2 commits intoapache:masterfrom
mailtoboggavarapu-coder:fix/input-stream-consumer-reader-leak
Apr 9, 2026
Merged

Fix BufferedReader resource leak in InputStreamConsumer#18469
danny0405 merged 2 commits intoapache:masterfrom
mailtoboggavarapu-coder:fix/input-stream-consumer-reader-leak

Conversation

@mailtoboggavarapu-coder
Copy link
Copy Markdown
Contributor

Describe the issue this Pull Request addresses

Problem

InputStreamConsumer.run() creates an InputStreamReader and BufferedReader inside a plain try block. If an exception occurs during br.lines().forEach(...), neither reader is closed, causing a resource leak.

Solution

Convert the plain try block to a try-with-resources statement that declares both InputStreamReader and BufferedReader as managed resources, ensuring they are automatically closed on both normal and exceptional exit.

Changes

  • hudi-cli/src/main/java/org/apache/hudi/cli/utils/InputStreamConsumer.java: Wrap InputStreamReader and BufferedReader construction in a try-with-resources statement in the run() method.

Summary and Changelog

Impact

Risk Level

Documentation Update

Contributor's checklist

  • Read through contributor's guide
  • Enough context is provided in the sections above
  • Adequate tests were added if applicable

@github-actions github-actions bot added the size:XS PR with lines of changes in <= 10 label Apr 5, 2026
Copy link
Copy Markdown
Contributor

@yihua yihua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This review was generated by an AI agent and may contain mistakes. Please verify any suggestions before applying.

Thanks for contributing! The intent of the fix is correct — converting to try-with-resources is the right approach for this resource leak. However, there's a stray ) on line 43 that introduces a syntax error and is blocking CI (the Azure build is already showing FAILURE). Just a one-character fix needed before this can land.

BufferedReader br = new BufferedReader(isr);
try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr)) {)
br.lines().forEach(log::info);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 There's a stray ) at the end of this line — )) {) — which is a syntax error and will prevent compilation. It should be )) { (no trailing paren). This is confirmed by the CI failure on this PR. Could you drop that extra ) and push a fix?

@hudi-bot
Copy link
Copy Markdown
Collaborator

hudi-bot commented Apr 7, 2026

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

Copy link
Copy Markdown
Contributor

@yihua yihua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This review was generated by an AI agent and may contain mistakes. Please verify any suggestions before applying.

LGTM — clean fix that correctly converts the plain try block to try-with-resources, ensuring both the InputStreamReader and BufferedReader are closed on both normal and exceptional exit.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.77%. Comparing base (76b4fa4) to head (f03a8a9).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
...org/apache/hudi/cli/utils/InputStreamConsumer.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #18469      +/-   ##
============================================
+ Coverage     68.53%   68.77%   +0.23%     
- Complexity    28037    28131      +94     
============================================
  Files          2444     2451       +7     
  Lines        134752   134986     +234     
  Branches      16292    16361      +69     
============================================
+ Hits          92356    92836     +480     
+ Misses        35112    34799     -313     
- Partials       7284     7351      +67     
Flag Coverage Δ
common-and-other-modules 44.42% <0.00%> (+0.07%) ⬆️
hadoop-mr-java-client 44.86% <ø> (-0.06%) ⬇️
spark-client-hadoop-common 48.40% <ø> (-0.06%) ⬇️
spark-java-tests 48.85% <ø> (+0.07%) ⬆️
spark-scala-tests 45.48% <ø> (-0.14%) ⬇️
utilities 38.22% <ø> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...org/apache/hudi/cli/utils/InputStreamConsumer.java 0.00% <0.00%> (ø)

... and 46 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danny0405 danny0405 merged commit eaa9c8b into apache:master Apr 9, 2026
53 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS PR with lines of changes in <= 10

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants