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: packets_connack_sent is not incremented if the ack_flag is non-zero #11520

Merged

Conversation

zhongwencool
Copy link
Member

@zhongwencool zhongwencool commented Aug 25, 2023

Fixes: https://emqx.atlassian.net/browse/EMQX-10840

Summary

🤖 Generated by Copilot at 28fd8d3

This pull request refactors the connection management logic from the emqx_cm module to the emqx_channel module, and updates the metrics and tests for the new format of the CONNACK packet. It also removes some unused functions and improves the performance of some channel operations by inlining functions.

PR Checklist

Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:

  • Added tests for the changes
  • Added property-based tests for code which performs user input validation
  • Changed lines covered in coverage report
  • Change log has been added to changes/(ce|ee)/(feat|perf|fix)-<PR-id>.en.md files
  • For internal contributor: there is a jira ticket to track this change
  • Created PR to emqx-docs if documentation update is required, or link to a follow-up jira ticket
  • Schema changes are backward compatible

Checklist for CI (.github/workflows) changes

  • If changed package build workflow, pass this action (manual trigger)
  • Change log has been added to changes/ dir for user-facing artifacts update

@zhongwencool zhongwencool requested review from lafirest and a team as code owners August 25, 2023 07:10

-spec connection_closed(emqx_types:clientid(), chan_pid()) -> true.
connection_closed(ClientId, ChanPid) ->
ets:delete_object(?CHAN_CONN_TAB, {ClientId, ChanPid}).
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I remember at least the function was left unchanged previously by @savonarola
but I cannot recall the discussion about why delete_object is still here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I added a clarification in 4.4
https://github.com/emqx/emqx/blob/main-v4.4/src/emqx_cm.erl#L173

%% We can't clean CHAN_CONN_TAB because records for dead connections
%% are required for `get_chann_conn_mod/1` function, and `get_chann_conn_mod/1`
%% is used for takeover.

I left the fun empty to avoid attempts to "fix" the things while we have the current mechanism of keeping offline sessions.

@zhongwencool zhongwencool force-pushed the packet-connack-sent-count-error branch from 28fd8d3 to fc17381 Compare August 25, 2023 07:18
@@ -493,7 +493,7 @@ inc_sent(Packet) ->
inc('packets.sent'),
do_inc_sent(Packet).

do_inc_sent(?CONNACK_PACKET(ReasonCode)) ->
Copy link
Member Author

Choose a reason for hiding this comment

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

-define(CONNACK_PACKET(ReasonCode), #mqtt_packet{
    header = #mqtt_packet_header{type = ?CONNACK},
    variable = #mqtt_packet_connack{
        ack_flags = 0,
        reason_code = ReasonCode
    }
}).

?CONNACK_PACKET/1 lock the ack_flags to 0.

@zhongwencool zhongwencool merged commit b59ec09 into emqx:release-52 Aug 25, 2023
129 of 130 checks passed
@zhongwencool zhongwencool deleted the packet-connack-sent-count-error branch August 25, 2023 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants