[
https://issues.apache.org/jira/browse/KAFKA-20996?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18109338#comment-18109338
]
Gergely Harmadás commented on KAFKA-20996:
------------------------------------------
Hi [~showuon], I have looked into this issue. Currently `getHostName` is used
in four places:
*
[UpdateVoterHandler|https://github.com/apache/kafka/blob/04c326d9d5bfb43127157e72d00d2d8d3395e1ac/raft/src/main/java/org/apache/kafka/raft/internals/UpdateVoterHandler.java#L190]
*
[AddVoterHandler|https://github.com/apache/kafka/blob/04c326d9d5bfb43127157e72d00d2d8d3395e1ac/raft/src/main/java/org/apache/kafka/raft/internals/AddVoterHandler.java#L208]
*
[SaslChannelBuilder|https://github.com/apache/kafka/blob/04c326d9d5bfb43127157e72d00d2d8d3395e1ac/clients/src/main/java/org/apache/kafka/common/network/SaslChannelBuilder.java#L236]
*
[SaslServerAuthenticator|https://github.com/apache/kafka/blob/04c326d9d5bfb43127157e72d00d2d8d3395e1ac/clients/src/main/java/org/apache/kafka/common/security/authenticator/SaslServerAuthenticator.java#L213]
Based on a quick check the first two KRaft-related usages are a trivial fix.
Those instances are created with InetSocketAddress.createUnresolved(host, port)
so there is no actual reverse lookup taking place. Still it would be cleaner to
use `getHostString` instead as this API actually guarantees no DNS queries.
For
[SaslServerAuthenticator|https://github.com/apache/kafka/blob/04c326d9d5bfb43127157e72d00d2d8d3395e1ac/clients/src/main/java/org/apache/kafka/common/security/authenticator/SaslServerAuthenticator.java#L213]
there is already a [PR|https://github.com/apache/kafka/pull/22569] ready
coming from the related issue KAFKA-19919.
I can cover
[SaslChannelBuilder|https://github.com/apache/kafka/blob/04c326d9d5bfb43127157e72d00d2d8d3395e1ac/clients/src/main/java/org/apache/kafka/common/network/SaslChannelBuilder.java#L236]
plus the two KRaft handlers under this ticket.
> `InetAddress.getHostName` could take long to impact network thread
> ------------------------------------------------------------------
>
> Key: KAFKA-20996
> URL: https://issues.apache.org/jira/browse/KAFKA-20996
> Project: Kafka
> Issue Type: Improvement
> Reporter: Luke Chen
> Priority: Major
>
> We use
> `InetAddress.getHostName`([javadoc|https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/InetAddress.html#getHostName()])
> in some places in kafka, but we never consider it might take long time to
> respond because it performs a reverse hostname lookup. When this happens,
> it'll block the network thread and cause unexpected timeout and hard to
> troubleshoot. We should improve this behavior.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)