Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(emqx_channel): do not log stale sock_close event as error #11975

Merged
merged 2 commits into from Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/emqx/src/emqx_channel.erl
Expand Up @@ -1246,8 +1246,10 @@ handle_info(
{ok, Channel3} -> {ok, ?REPLY_EVENT(disconnected), Channel3};
Shutdown -> Shutdown
end;
handle_info({sock_closed, Reason}, Channel = #channel{conn_state = disconnected}) ->
?SLOG(error, #{msg => "unexpected_sock_close", reason => Reason}),
handle_info({sock_closed, _Reason}, Channel = #channel{conn_state = disconnected}) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we also translate MQTT.disconnect to sock_closed some where.

Need double check

Copy link
Member Author

@zmstone zmstone Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do, it's in emqx_connection.erl.
it's one of the causes of this race:

  1. receive DISCONNECT (being processed), and tcp_closed (in the mailbox)
  2. handle DISCONNECT as: a) close socket, b) mark conn_state as disconnected
  3. handle tcp_closed at disconnected state.

%% This can happen as a race:
%% EMQX closes socket and marks 'disconnected' but 'tcp_closed' or 'ssl_closed'
%% is already in process mailbox
{ok, Channel};
handle_info(clean_authz_cache, Channel) ->
ok = emqx_authz_cache:empty_authz_cache(),
Expand Down
9 changes: 4 additions & 5 deletions apps/emqx_gateway_stomp/src/emqx_stomp_channel.erl
Expand Up @@ -963,13 +963,12 @@ handle_info(
NChannel = ensure_disconnected(Reason, Channel),
shutdown(Reason, NChannel);
handle_info(
{sock_closed, Reason},
{sock_closed, _Reason},
Channel = #channel{conn_state = disconnected}
) ->
?SLOG(error, #{
msg => "unexpected_sock_closed",
reason => Reason
}),
%% This can happen as a race:
%% EMQX closes socket and marks 'disconnected' but 'tcp_closed' or 'ssl_closed'
%% is already in process mailbox
{ok, Channel};
handle_info(clean_authz_cache, Channel) ->
ok = emqx_authz_cache:empty_authz_cache(),
Expand Down