You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Greg Harris (Jira)" <ji...@apache.org> on 2023/11/13 19:00:00 UTC
[jira] [Created] (KAFKA-15815) JsonRestServer leaks sockets via HttpURLConnection when keep-alive enabled
Greg Harris created KAFKA-15815:
-----------------------------------
Summary: JsonRestServer leaks sockets via HttpURLConnection when keep-alive enabled
Key: KAFKA-15815
URL: https://issues.apache.org/jira/browse/KAFKA-15815
Project: Kafka
Issue Type: Bug
Affects Versions: 3.6.0
Reporter: Greg Harris
By default HttpURLConnection has keep-alive enabled, which allows a single HttpURLConnection to be left open in order to be re-used for later requests. This means that despite JsonRestServer calling `close()` on the relevant InputStream, and calling `disconnect()` on the connection itself, the HttpURLConnection does not call `close()` on the underlying socket.
This affects the Trogdor AgentTest and CoordinatorTest suites, where most of the methods make HTTP requests using the JsonRestServer. The effect is that ~32 sockets are leaked per test run, all remaining in the CLOSE_WAIT state (half closed) after the test. This is because the JettyServer has correctly closed the connections, but the HttpURLConnection has not.
There does not appear to be a way to locally override the HttpURLConnection's behavior in this case, and only disabling keep-alive overall (via the system property `http.keepAlive=false`) seems to resolve the socket leaks.
To prevent the leaks, we can move JsonRestServer to an alternative HTTP implementation, perhaps the jetty-client that Connect uses, or disable keepAlive during tests.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)