Make CompositeInputStream safe when close() races with an in-progress read - #16471
Open
LI123456mo wants to merge 2 commits into
Open
LI123456mo wants to merge 2 commits into
LI123456mo wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change?
Fixes #16458
CompositeInputStreamis 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 rawIOException("Stream already closed") from a read, andavailable()can keep reporting data after the stream has been closed.Brief changelog
addInputStream, bothreadmethods,availableandclosesynchronized, soclose()waits for an in-flight read instead of closing streams underneath it.closedflag:available()returns 0 once closed, and anIOExceptionfrom an already-closed underlying stream is treated as end of stream instead of being surfaced.Verifying this change
Added
CompositeInputStreamConcurrencyTest(5 tests):read(byte[])andread()interrupted byclose()report end of stream (no raw exception)close()happens during a readavailable()returns 0 whileclose()is in progressclose()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