Skip to content

Commit 1f29d90

Browse files
Merge pull request #2731 from rabbitmq/rabbitmq-server-2730
Avoid double resolving client hostname (cherry picked from commit 06e242a)
1 parent 1a09f95 commit 1f29d90

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

deps/rabbit/src/rabbit_reader.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,16 @@ auth_phase(Response,
14131413
auth_mechanism = {Name, AuthMechanism},
14141414
auth_state = AuthState},
14151415
sock = Sock}) ->
1416-
RemoteAddress = list_to_binary(inet:ntoa(Connection#connection.host)),
1416+
rabbit_log:debug("Raw client connection hostname during authN phase: ~p", [Connection#connection.host]),
1417+
RemoteAddress = case Connection#connection.host of
1418+
%% the hostname was already resolved, e.g. by reverse DNS lookups
1419+
Bin when is_binary(Bin) -> Bin;
1420+
%% the hostname is an IP address
1421+
Tuple when is_tuple(Tuple) ->
1422+
rabbit_data_coercion:to_binary(inet:ntoa(Connection#connection.host));
1423+
Other -> rabbit_data_coercion:to_binary(Other)
1424+
end,
1425+
rabbit_log:debug("Resolved client hostname during authN phase: ~s", [RemoteAddress]),
14171426
case AuthMechanism:handle_response(Response, AuthState) of
14181427
{refused, Username, Msg, Args} ->
14191428
rabbit_core_metrics:auth_attempt_failed(RemoteAddress, Username, amqp091),

0 commit comments

Comments
 (0)