googleapis / googleapis/google-http-java-client

HttpRequest#executeAsync leaks a thread on every call

Đang mở
#2,122 0 bình luận 2 reaction 0 người được giao Xem trên GitHub
priority: p3 type: bug
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

Mô tả

The `executeAsync` method of `com.google.api.client.http.HttpRequest` currently leaks a thread on every call; this means that multiple calls to the method will eventually exhaust all memory.

A quick inspection of [the code for this method](https://github.com/googleapis/google-http-java-client/blob/main/google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java#L1156-L1160) shows that it creates a new thread pool on every call, and never shuts the pool down.

### Steps to replicate

This issue can be easily replicated in a unit test; for example, the following code (added in `HttpRequestTest.java`) will fail with an `OutOfMemoryError` due to an inability to create a new thread.

```java
@Test
public void testThreadLeak() throws Exception {
for (int i = 0; i < 1000000; i++) {
RedirectTransport fakeTransport = new RedirectTransport();
HttpRequest request =
fakeTransport.createRequestFactory().buildGetRequest(new GenericUrl("http://gmail.com"));
Future resp = request.executeAsync();
resp.get();
}
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.