Skip to content

HttpRequest#executeAsync leaks a thread on every call #2122

Open

Description

@gabrielreid

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 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.

  @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<HttpResponse> resp = request.executeAsync();
      resp.get();
    }
  }

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Feb 5, 2026
  2. added
    priority: p3Desirable enhancement or fix. May not be included in next release.
    and removed
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p3Desirable enhancement or fix. May not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions