LI123456mo opened a new pull request, #16471:
URL: https://github.com/apache/dubbo/pull/16471
## 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
- [x] Make sure there is a GitHub_issue field for the change.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Write necessary unit-test to verify your logic correction.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]