Core: LowLevelHttpResponse not disconnected when HttpResponse construction throws RuntimeException
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 84/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- java
- Lĩnh vực
- networking
Hướng nghiên cứu
Bắt đầu trong google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java, tập trung vào HttpRequest.execute() và khối finally của nó. Tái hiện lỗi bằng một LowLevelHttpResponse có getContentEncoding() ném ra ngoại lệ, sau đó chạy testExecute_disconnectOnResponseConstructionFailure. Hoàn tất khi phản hồi cấp thấp được ngắt kết nối nếu việc xây dựng phản hồi thất bại và kiểm thử hồi quy vượt qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 1.4k
- Fork
- 473
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của googleapis/google-http-java-client
-
GenericData.containsKey() returns true for unset (null) declared fields, violating Map contract Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
googleapis/google-http-java-client#2187 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
type: cleanup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
priority: p2 type: cleanup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Tất cả issue của googleapis/google-http-java-client
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
infinispan/infinispan#18150 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
opensearch-project/k-NN#3597 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100