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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(emqx_mgmt): catch OOM shutdown exits properly when calling a conn procces #12814

Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 15 additions & 1 deletion apps/emqx_management/src/emqx_mgmt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -711,5 +711,19 @@ call_conn(ConnMod, Pid, Req) ->
exit:R when R =:= shutdown; R =:= normal ->
{error, shutdown};
exit:{R, _} when R =:= shutdown; R =:= noproc ->
{error, shutdown}
{error, shutdown};
exit:{{shutdown, _OOMInfo}, _Location} ->
{error, shutdown};
exit:timeout ->
?SLOG(
warning,
#{
msg => "call_client_connection_process_timeout",
request => Req,
pid => Pid,
module => ConnMod,
stacktrace => erlang:process_info(Pid, current_stacktrace)
}
),
{error, timeout}
end.
2 changes: 2 additions & 0 deletions apps/emqx_management/src/emqx_mgmt_api_clients.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,8 @@ list_client_msgs(MsgType, ClientID, QString) ->
code => 'NOT_IMPLEMENTED',
message => <<"API not implemented for persistent sessions">>
}};
{error, Reason} ->
?INTERNAL_ERROR(Reason);
{Msgs, Meta = #{}} when is_list(Msgs) ->
format_msgs_resp(MsgType, Msgs, Meta, QString)
end
Expand Down
4 changes: 4 additions & 0 deletions changes/ce/fix-12814.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Handle several errors in `/clients/{clientid}/mqueue_messages` and `/clients/{clientid}/inflight_messages` APIs:

- Internal timeout, which means that EMQX failed to get the list of Inflight/Mqueue messages within the default timeout of 5 s. This error may occur when the system is under a heavy load. The API will return 500 `{"code":"INTERNAL_ERROR","message":"timeout"}` response and log additional details.
Copy link
Member

Choose a reason for hiding this comment

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

Could be that the client process is stuck. Maybe even worth logging the current stacktrace from process_info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a client proc stacktrace to the log event.

- Client shutdown. The error may occur if the client connection is shutdown during the API call. The API will return 404 `{"code": "CLIENT_SHUTDOWN", "message": "Client connection has been shutdown"}` response in this case.