Do not emit stats if connection has not been stablished

Ensures stats are not emitted until the connection is stablished.
A non-pid value crashes the stats gc.

rabbitmq-management-agent#42
This commit is contained in:
Diana Corbacho 2017-04-06 12:08:30 +01:00
parent 2da7008647
commit f124727c3b
1 changed files with 5 additions and 0 deletions

View File

@ -186,6 +186,11 @@ maybe_emit_stats(State) ->
rabbit_event:if_enabled(State, #state.stats_timer,
fun() -> emit_stats(State) end).
emit_stats(State=#state{connection = C}) when C == none; C == undefined ->
%% Avoid emitting stats on terminate when the connection has not yet been
%% established, as this causes orphan entries on the stats database
State1 = rabbit_event:reset_stats_timer(State, #state.stats_timer),
State1;
emit_stats(State=#state{socket=Sock, connection=Conn}) ->
SockInfos = case rabbit_net:getstat(Sock,
[recv_oct, recv_cnt, send_oct, send_cnt, send_pend]) of