Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit 44eba79

Browse files
Ditto for prematurely [but explicitly] closed client TCP connections
1 parent 330252c commit 44eba79

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/rabbit_reader.erl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ start_connection(Parent, HelperSup, Deb, Sock) ->
422422
log_connection_exception(Name, Ex) ->
423423
Severity = case Ex of
424424
connection_closed_with_no_data_received -> debug;
425+
{connection_closed_abruptly, _} -> warning;
425426
connection_closed_abruptly -> warning;
426427
_ -> error
427428
end,
@@ -431,6 +432,17 @@ log_connection_exception(Severity, Name, {heartbeat_timeout, TimeoutSec}) ->
431432
%% Long line to avoid extra spaces and line breaks in log
432433
log(Severity, "closing AMQP connection ~p (~s):~nmissed heartbeats from client, timeout: ~ps~n",
433434
[self(), Name, TimeoutSec]);
435+
log_connection_exception(Severity, Name, {connection_closed_abruptly,
436+
#v1{connection = #connection{user = #user{username = Username},
437+
vhost = VHost}}}) ->
438+
log(Severity, "closing AMQP connection ~p (~s, vhost: '~s', user: '~s'):~nclient unexpectedly closed TCP connection~n",
439+
[self(), Name, VHost, Username]);
440+
%% when client abruptly closes connection before connection.open/authentication/authorization
441+
%% succeeded, don't log username and vhost as 'none'
442+
log_connection_exception(Severity, Name, {connection_closed_abruptly, _}) ->
443+
log(Severity, "closing AMQP connection ~p (~s):~nclient unexpectedly closed TCP connection~n",
444+
[self(), Name]);
445+
%% old exception structure
434446
log_connection_exception(Severity, Name, connection_closed_abruptly) ->
435447
log(Severity, "closing AMQP connection ~p (~s):~nclient unexpectedly closed TCP connection~n",
436448
[self(), Name]);
@@ -528,7 +540,7 @@ stop(tcp_healthcheck, State) ->
528540
throw(connection_closed_with_no_data_received);
529541
stop(closed, State) ->
530542
maybe_emit_stats(State),
531-
throw(connection_closed_abruptly);
543+
throw({connection_closed_abruptly, State});
532544
stop(Reason, State) ->
533545
maybe_emit_stats(State),
534546
throw({inet_error, Reason}).
@@ -1138,7 +1150,7 @@ handle_method0(MethodName, FieldsBin,
11381150
State)
11391151
catch throw:{inet_error, E} when E =:= closed; E =:= enotconn ->
11401152
maybe_emit_stats(State),
1141-
throw(connection_closed_abruptly);
1153+
throw({connection_closed_abruptly, State});
11421154
exit:#amqp_error{method = none} = Reason ->
11431155
handle_exception(State, 0, Reason#amqp_error{method = MethodName});
11441156
Type:Reason ->

0 commit comments

Comments
 (0)