googleapis / googleapis/google-http-java-client

HttpRequest#executeAsync leaks a thread on every call

Open
#2,122 0 comments 2 reactions 0 assignees View on GitHub
priority: p3 type: bug
Dominant language
Java
Stars
1.4k
Forks
473
PR merge metrics
No merged PRs in 30d

Description

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();
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.