Core: LowLevelHttpResponse not disconnected when HttpResponse construction throws RuntimeException
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 84/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- java
- 領域
- networking
調査の方向性
google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java から始め、HttpRequest.execute() とその finally ブロックに注目してください。getContentEncoding() が例外をスローする LowLevelHttpResponse で失敗を再現し、その後 testExecute_disconnectOnResponseConstructionFailure を実行してください。レスポンスの構築に失敗したときに低レベルレスポンスが切断され、回帰テストに合格すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Environment details:
- Core — HttpRequest.execute() in google-http-client
- OS type and version: Any (not OS-specific)
- Java version: Any (reproduces on Java 8+)
- google-http-client version(s): reproducible on current main
Steps to reproduce:
- Implement a LowLevelHttpResponse whose getContentEncoding() throws a RuntimeException.
- Execute an HttpRequest against that transport.
- Catch the RuntimeException from execute().
- Observe disconnect() was never called on the low-level response.
Code example:
MockLowLevelHttpResponse failingResponse = new MockLowLevelHttpResponse() {
@Override
public String getContentEncoding() {
throw new RuntimeException("simulated failure");
}
};
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest().setResponse(failingResponse);
}
};
HttpRequest req = transport.createRequestFactory()
.buildGetRequest(new GenericUrl("http://example.com"));
try {
req.execute();
} catch (RuntimeException e) {
// failingResponse.isDisconnected() == false <-- BUG: socket leaked
}
Stack trace:
None — silent resource leak, not a crash. The RuntimeException propagates as expected; the
bug is that execute()'s finally block never calls LowLevelHttpResponse#disconnect() here.
External references:
- HttpRequest#execute(): google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java
Any additional information:
Under sustained error conditions, leaked connections accumulate until the pool is exhausted,
risking DoS/thread starvation. Pre-existing bug, unrelated to security hardening — found
opportunistically during a security audit of this file.
Proposed fix — in execute()'s finally block, add a guarded disconnect():
} finally {
if (!responseConstructed && lowLevelHttpResponse != null) {
try {
InputStream c = lowLevelHttpResponse.getContent();
if (c != null) c.close();
} catch (IOException ignored) {}
try {
lowLevelHttpResponse.disconnect();
} catch (IOException ignored) {}
}
}
Regression test testExecute_disconnectOnResponseConstructionFailure included in the
accompanying PR.
- 主要言語
- Java
- スター
- 1.4k
- フォーク
- 473
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
googleapis/google-http-java-client のほかの issue
-
GenericData.containsKey() returns true for unset (null) declared fields, violating Map contract オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
googleapis/google-http-java-client#2187 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
type: cleanup
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
priority: p2 type: cleanup
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
googleapis/google-http-java-client の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
infinispan/infinispan#18150 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
opensearch-project/k-NN#3597 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100