Skip to content

Make CompositeInputStream safe when close() races with an in-progress read - #16471

Open
LI123456mo wants to merge 2 commits into
apache:3.3from
LI123456mo:fix-composite-input-stream-16458
Open

LI123456mo wants to merge 2 commits into
apache:3.3from
LI123456mo:fix-composite-input-stream-16458

Conversation

@LI123456mo

Copy link
Copy Markdown
Contributor

What is the purpose of the change?

Fixes #16458

CompositeInputStream is not thread-safe. When a client connection drops during HTTP/2 streaming, close() can run on the I/O thread while a worker thread is still reading from the same stream. That can surface a raw IOException ("Stream already closed") from a read, and available() can keep reporting data after the stream has been closed.

Brief changelog

  • Made addInputStream, both read methods, available and close synchronized, so close() waits for an in-flight read instead of closing streams underneath it.
  • Added a closed flag: available() returns 0 once closed, and an IOException from an already-closed underlying stream is treated as end of stream instead of being surfaced.

Verifying this change

Added CompositeInputStreamConcurrencyTest (5 tests):

  • read(byte[]) and read() interrupted by close() report end of stream (no raw exception)
  • already-buffered data is still delivered when close() happens during a read
  • available() returns 0 while close() is in progress
  • close() waits for a read in progress (two-thread test)

Before the change, 4 of these 5 fail; the fifth is a regression guard that passes either way. After the change, all pass.

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction.

@codecov-commenter

codecov-commenter commented Sep 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.15385% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.91%. Comparing base (6054104) to head (15f1566).
⚠️ Report is 12 commits behind head on 3.3.

Files with missing lines Patch % Lines
...he/dubbo/remoting/http12/CompositeInputStream.java 46.15% 10 Missing and 4 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##                3.3   #16471       +/-   ##
=============================================
+ Coverage     36.93%   60.91%   +23.98%     
+ Complexity    11752       15    -11737     
=============================================
  Files          1952     1953        +1     
  Lines         89249    89291       +42     
  Branches      13389    13477       +88     
=============================================
+ Hits          32961    54389    +21428     
+ Misses        51710    29307    -22403     
- Partials       4578     5595     +1017     
Flag Coverage Δ
integration-tests-java21 32.13% <23.07%> (+0.05%) ⬆️
integration-tests-java8 32.21% <23.07%> (+<0.01%) ⬆️
samples-tests-java21 32.17% <23.07%> (-0.01%) ⬇️
samples-tests-java8 29.83% <23.07%> (+0.03%) ⬆️
unit-tests-java11 59.16% <46.15%> (?)
unit-tests-java17 58.66% <46.15%> (?)
unit-tests-java21 58.65% <46.15%> (?)
unit-tests-java25 58.62% <46.15%> (?)
unit-tests-java8 59.19% <46.15%> (?)

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

[Bug] Make composite input stream handling safe when stream close races with an in-progress read

2 participants