Cache evection of HTTP Client lead to not closed HttpClients
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 41
- フォーク
- 33
- 平均マージ
- 18時間 34分
- マージ済み PR(30日)
- 19
説明
Describe the Bug
The current implementation of caching and evicting an HTTP Client lead to not closed HttpClients.
Technically the HttpClients are CloseableHttpClient and should / need(specifically for pooled connections) to be closed after usage.
(See also this discussion)
In the current code-base, when a HttpClient with a PoolingHttpClientConnectionManager is created, it's not cleaned up properly on eviction.
The following workaround does not work in all cases:
cache = Caffeine.newBuilder().expireAfterAccess(duration, unit).ticker(ticker).evictionListener((key, value, cause) -> {
if (value instanceof CloseableHttpClient closeableHttpClient) {
try {
closeableHttpClient.close();
} catch (final Exception e) {
log.warn("Failed to close HttpClient. Ignoring the exception and continue.", e);
}
}
}).build();
There are two basic scenarios:
- The client was created and is no longer in use and the eviction time triggers the cleanup. ✅
- The client was created and in still in use (long running operation, async operation, ...) and the eviction time triggers the cleanup. Then the
evictionListenerwould kill the connection underneath. ❌
Steps to Reproduce
Code review.
Expected Behavior
Proper closing of HttpClients.
Screenshots
No response
Used Versions
Current state in main.
Code Examples
// Your code here
Stack Trace
No response
Log File
Log file
...Affected Development Phase
Development
Impact
No Impact
Timeline
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされたキャッシュ構築箇所の DefaultApacheHttpClient5Cache.java から始め、issue 755 の議論を確認してください。長時間実行される操作や非同期操作中に、プールされた CloseableHttpClients がどのように作成、キャッシュ、排除、使用されるかを追跡してください。排除されたクライアントが、まだ使用中のクライアントを中断せずにクローズされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- networking
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 32/100