Skip to content

Prevent OkHttp idle threads from blocking JVM shutdown #1267

@svetanis

Description

@svetanis

Prevent OkHttp idle threads from blocking JVM shutdown

The ADK framework does not cleanly terminate the JVM upon process completion when making chat completions requests because the HTTP clients are spawning non-daemon threads with a keep-alive timeout.

Please make sure you read the contribution guide and file the issues in the right place.
Contribution guide.

🔴 Required Information

Describe the Bug:
When building an agent application using the ADK, the JVM hangs while waiting for background threads to timeout after all tasks have finished instead of cleanly exiting with code 0. This occurs because ChatCompletionsHttpClient and the internal Gemini API client construct default OkHttpClient instances. The default OkHttp connection pool uses a ThreadPoolExecutor that produces non-daemon threads. These threads prevent the JVM from shutting down until their keep-alive timer expires.

Steps to Reproduce:

  1. Create a basic ADK agent application that makes a model request (e.g., ToolsDemoApp).
  2. Run the application from an IDE or terminal.
  3. Observe that after the final standard output logs are printed, the Java process remains active and hung before finally terminating.

Expected Behavior:
The JVM should exit cleanly immediately after the main thread finishes execution. The internal HTTP clients used by the ADK should be configured to use daemon threads so they do not block JVM termination.

Observed Behavior:
The JVM process hangs because OkHttp non-daemon threads are kept alive in the connection pool.

Environment Details:

  • ADK Library Version: 1.4.1-SNAPSHOT
  • OS: Windows (also reproducible on macOS/Linux)
  • TS Version: N/A

Model Information:

  • Which model is being used: groq/llama-3.3-70b-versatile / gemini-2.5-flash

🟡 Optional Information

Regression:
No.

How often has this issue occurred?:

  • Always (100%)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions