Skip to content

Commit

Permalink
Merge pull request #11 from zotonic/fix-session-present-connack
Browse files Browse the repository at this point in the history
Set session_present when needed in connect
  • Loading branch information
mmzeeman authored Aug 26, 2022
2 parents aead3f8 + cf1053a commit cd61698
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
otp_version: [22.3, 23.3, 24.0.1]
otp_version: [23, 24, 25]
os: [ubuntu-latest]

container:
Expand Down
14 changes: 12 additions & 2 deletions src/mqtt_sessions_process.erl
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,24 @@ handle_connect_auth(Msg, Options, StateIfAccept, #state{ runtime = Runtime, is_s
%% If an Auth message is sent then we need further authenticaion handshakes.
%% Only after a succesful connack we will set the is_session_present flag.
handle_connect_auth_1({ok, #{ type := connack, reason_code := ?MQTT_RC_SUCCESS } = ConnAck, UserContext1},
#{ clean_start := CleanStart }, StateIfAccept, _State) ->
#{ clean_start := CleanStart }, StateIfAccept, #state{ is_session_present = IsSessionPresent }) ->
StateCleaned = maybe_clean_start(CleanStart, StateIfAccept),

%% Set the session_present flag to true, when the runtime omitted it, and when there is a
%% session present.
ConnAck1 = case maps:find(session_present, ConnAck) of
{ok, _} -> ConnAck;
error ->
ConnAck#{ session_present => IsSessionPresent andalso not (CleanStart =:= true) }
end,

State1 = StateCleaned#state{
user_context = UserContext1,
is_session_present = true,
will = undefined
},
State2 = reply_connack(ConnAck, State1),

State2 = reply_connack(ConnAck1, State1),
mqtt_sessions_will:connected(State2#state.will_pid, StateIfAccept#state.will,
State2#state.session_expiry_interval, State2#state.user_context),
State3 = resend_unacknowledged( cleanup_pending(State2) ),
Expand Down

0 comments on commit cd61698

Please sign in to comment.