adk-java icon indicating copy to clipboard operation
adk-java copied to clipboard

Prevent OkHttp idle threads from blocking JVM shutdown

Open svetanis opened this issue 5 months ago • 2 comments

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%)

svetanis avatar Jun 13 '26 19:06 svetanis

Hi @svetanis, Thanks for reporting this issue and and We appreciate you taking the time to submit this pull request. am able to reproduce this behavior which you described. Currently this Issue and PR are under review by our team, we will keep you update if any additional information is required. thank you.

hemasekhar-p avatar Jun 15 '26 11:06 hemasekhar-p

@anFatum, Please take a look into it.

hemasekhar-p avatar Jun 15 '26 11:06 hemasekhar-p