camel-openai: close OpenAI client on endpoint stop to prevent OkHttp thread leak#23531
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
All tested modules (8 modules)
|
| returnDirectTools.clear(); | ||
| } | ||
| if (client != null) { | ||
| client.close(); |
There was a problem hiding this comment.
Should we enclose in a try catch as it is done for the mcp clients?
There was a problem hiding this comment.
Closes this client, relinquishing any underlying resources.
This is purposefully not inherited from AutoCloseable because the client is long-lived and usually should not be synchronously closed via try-with-resources.
this is from the .close() java doc, should be safe without a try catch
gnodet
left a comment
There was a problem hiding this comment.
Correct fix — calling client.close() before setting client = null in OpenAIEndpoint.doStop() ensures the HTTP client resources are properly released. Without this, the client would be leaked on endpoint stop.
LGTM.
Fully automatic review from Claude Code
Summary
client.close()inOpenAIEndpoint.doStop()before nulling the reference so that OkHttp's dispatcher executor, connection pool, and cache are properly shut down.OkHttp Dispatcher,OkHttp ConnectionPool) linger after route stop, especially visible underexec:javaor Camel JBang dev mode where the JVM does not exit.