-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java 21+: Ensure simple
client is closed
#1011
Comments
We can just use reflection. I don't think it would be a hot-path. The bigger issue is that our signatures currently return http4s-jdk-http-client/core/src/main/scala/org/http4s/jdkhttpclient/JdkHttpClient.scala Lines 247 to 248 in 21de6a2
|
Does it need reflection, or can it just pattern match on AutoCloseable? Why does it need to be a breaking change instead of another constructor? The bigger problem I see is that the resource release would be a no-op on older JDK. |
👍 smart
You're right, it doesn't. See a prior discussion on a similar issue where we decided to break: #770 (comment). |
That pattern match might require a nowarn when compiled on JDK21 for an unreachable fallback case. |
As Java 21+ allows explicitly closing clients, this adds new constructors that return the clients wrapped in a Resource. On older Java versions, the release is a no-op, on newer it enforces the cleanup of resources. Also ensures the websocket client closes the input channel on release so the connection gets properly closed. Closes http4s#1011
Java 21 adds methods to close a
HttpClient
and also makes it implementAutoCloseable
: https://bugs.openjdk.org/browse/JDK-8267140Ideally, http4s-jdk-http-client should leverage this and expose the
simple
client wrapped in aResource
to ensure the client is properly closed and cleaned up after use. Not sure how this can be achieved without requiring Java 21+ though, needs research.The text was updated successfully, but these errors were encountered: