-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix: packets_connack_sent is not incremented if the ack_flag is non-zero #11520
Conversation
|
||
-spec connection_closed(emqx_types:clientid(), chan_pid()) -> true. | ||
connection_closed(ClientId, ChanPid) -> | ||
ets:delete_object(?CHAN_CONN_TAB, {ClientId, ChanPid}). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?CHAN_CONN_TAB
table store{{ClientId, ChanPid, Mod}
, so ets:delete_object do anything here.- we have already deleted {clientid, ChanPid} in emqx_cm process after ChanPid shutdown here:
https://github.com/emqx/emqx/blob/master/apps/emqx/src/emqx_cm.erl#L686-L692
So we don't need this connection_closed/1 function now.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
… the CONNACK packet is non-zero
28fd8d3
to
fc17381
Compare
@@ -493,7 +493,7 @@ inc_sent(Packet) -> | |||
inc('packets.sent'), | |||
do_inc_sent(Packet). | |||
|
|||
do_inc_sent(?CONNACK_PACKET(ReasonCode)) -> |
There was a problem hiding this comment.
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.
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 theemqx_channel
module, and updates the metrics and tests for the new format of theCONNACK
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:
changes/(ce|ee)/(feat|perf|fix)-<PR-id>.en.md
filesChecklist for CI (.github/workflows) changes
changes/
dir for user-facing artifacts update