fix okhttpclient response body leak bug #600
Merged
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.
close #599
reproduce:
cleanup
function, whencleanup
found the connection in the pool is still in use but its reference is empty, thecleanup
will mark the connection is leaked and then will print the log and clear the connection.resolution
Rewrite the flush and read methods in http2Client. During flush, all the data streams of the response are taken out and given to a global buffer, and then close the response. During read, batches are read from the global buffer.
tests
复现场景:
要等待5分钟才出现日志是因为okhttp client内有一个connection pool,pool的cleanup任务是默认5分钟执行一次。上述日志便是cleanup时发现 池子中的connection还在使用但引用者为空,便认定该connection 泄漏,于是会打印日志并将其清除。
解决:
重构http2Client中flush和read的方式,在flush时将response 的全部数据流取出给到一个全局buffer, read时 一批批的从全局buffer中读取。
测试: