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

Commit 330252c

Browse files
Log vhost and username for cleanly closed connections
Doing so for abrupt closure cases requires augmenting exceptions thrown, including for socket errors ({inet_error, ...} and such). That is a more risky change which may or may not be worth the improvement: * Socket error formatting happens in multiple places * Plugins can use/depend on socket errors being primarily 2-tuples
1 parent 73f730c commit 330252c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/rabbit_reader.erl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,20 @@ start_connection(Parent, HelperSup, Deb, Sock) ->
387387
last_blocked_by = none,
388388
last_blocked_at = never}},
389389
try
390-
run({?MODULE, recvloop,
391-
[Deb, [], 0, switch_callback(rabbit_event:init_stats_timer(
392-
State, #v1.stats_timer),
393-
handshake, 8)]}),
394-
log(info, "closing AMQP connection ~p (~s)~n", [self(), dynamic_connection_name(Name)])
390+
case run({?MODULE, recvloop,
391+
[Deb, [], 0, switch_callback(rabbit_event:init_stats_timer(
392+
State, #v1.stats_timer),
393+
handshake, 8)]}) of
394+
%% connection was closed cleanly by the client
395+
#v1{connection = #connection{user = #user{username = Username},
396+
vhost = VHost}} ->
397+
log(info, "closing AMQP connection ~p (~s, vhost: '~s', user: '~s')~n",
398+
[self(), dynamic_connection_name(Name), VHost, Username]);
399+
%% just to be more defensive
400+
_ ->
401+
log(info, "closing AMQP connection ~p (~s)~n",
402+
[self(), dynamic_connection_name(Name)])
403+
end
395404
catch
396405
Ex ->
397406
log_connection_exception(dynamic_connection_name(Name), Ex)
@@ -490,7 +499,7 @@ mainloop(Deb, Buf, BufLen, State = #v1{sock = Sock,
490499
recvloop(Deb, [Data | Buf], BufLen + size(Data),
491500
State#v1{pending_recv = false});
492501
closed when State#v1.connection_state =:= closed ->
493-
ok;
502+
State;
494503
closed when CS =:= pre_init andalso Buf =:= [] ->
495504
stop(tcp_healthcheck, State);
496505
closed ->
@@ -506,7 +515,7 @@ mainloop(Deb, Buf, BufLen, State = #v1{sock = Sock,
506515
?MODULE, Deb, {Buf, BufLen, State});
507516
{other, Other} ->
508517
case handle_other(Other, State) of
509-
stop -> ok;
518+
stop -> State;
510519
NewState -> recvloop(Deb, Buf, BufLen, NewState)
511520
end
512521
end.

0 commit comments

Comments
 (0)