fix(emqx_gateway): fix the function_clause error when client disconnect after connection created
This commit is contained in:
parent
e6d7e59c18
commit
cfe2954a88
|
@ -98,10 +98,10 @@ info(ctx, #channel{ctx = Ctx}) ->
|
||||||
stats(_) ->
|
stats(_) ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init(ConnInfo = #{peername := {PeerHost, _},
|
init(ConnInfoT = #{peername := {PeerHost, _},
|
||||||
sockname := {_, SockPort}},
|
sockname := {_, SockPort}},
|
||||||
#{ctx := Ctx} = Config) ->
|
#{ctx := Ctx} = Config) ->
|
||||||
Peercert = maps:get(peercert, ConnInfo, undefined),
|
Peercert = maps:get(peercert, ConnInfoT, undefined),
|
||||||
Mountpoint = maps:get(mountpoint, Config, <<>>),
|
Mountpoint = maps:get(mountpoint, Config, <<>>),
|
||||||
ListenerId = case maps:get(listener, Config, undefined) of
|
ListenerId = case maps:get(listener, Config, undefined) of
|
||||||
undefined -> undefined;
|
undefined -> undefined;
|
||||||
|
@ -123,6 +123,10 @@ init(ConnInfo = #{peername := {PeerHost, _},
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
||||||
|
%% because it is possible to disconnect after init, and then trigger the $event.disconnected hook
|
||||||
|
%% and these two fields are required in the hook
|
||||||
|
ConnInfo = ConnInfoT#{proto_name => <<"CoAP">>, proto_ver => <<"1">>},
|
||||||
|
|
||||||
Heartbeat = ?GET_IDLE_TIME(Config),
|
Heartbeat = ?GET_IDLE_TIME(Config),
|
||||||
#channel{ ctx = Ctx
|
#channel{ ctx = Ctx
|
||||||
, conninfo = ConnInfo
|
, conninfo = ConnInfo
|
||||||
|
@ -349,8 +353,6 @@ ensure_connected(Channel = #channel{ctx = Ctx,
|
||||||
conninfo = ConnInfo,
|
conninfo = ConnInfo,
|
||||||
clientinfo = ClientInfo}) ->
|
clientinfo = ClientInfo}) ->
|
||||||
NConnInfo = ConnInfo#{ connected_at => erlang:system_time(millisecond)
|
NConnInfo = ConnInfo#{ connected_at => erlang:system_time(millisecond)
|
||||||
, proto_name => <<"COAP">>
|
|
||||||
, proto_ver => <<"1">>
|
|
||||||
},
|
},
|
||||||
ok = run_hooks(Ctx, 'client.connected', [ClientInfo, NConnInfo]),
|
ok = run_hooks(Ctx, 'client.connected', [ClientInfo, NConnInfo]),
|
||||||
_ = run_hooks(Ctx, 'client.connack', [NConnInfo, connection_accepted, []]),
|
_ = run_hooks(Ctx, 'client.connack', [NConnInfo, connection_accepted, []]),
|
||||||
|
|
|
@ -93,10 +93,10 @@ info(ctx, #channel{ctx = Ctx}) ->
|
||||||
stats(_) ->
|
stats(_) ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init(ConnInfo = #{peername := {PeerHost, _},
|
init(ConnInfoT = #{peername := {PeerHost, _},
|
||||||
sockname := {_, SockPort}},
|
sockname := {_, SockPort}},
|
||||||
#{ctx := Ctx} = Config) ->
|
#{ctx := Ctx} = Config) ->
|
||||||
Peercert = maps:get(peercert, ConnInfo, undefined),
|
Peercert = maps:get(peercert, ConnInfoT, undefined),
|
||||||
Mountpoint = maps:get(mountpoint, Config, undefined),
|
Mountpoint = maps:get(mountpoint, Config, undefined),
|
||||||
ListenerId = case maps:get(listener, Config, undefined) of
|
ListenerId = case maps:get(listener, Config, undefined) of
|
||||||
undefined -> undefined;
|
undefined -> undefined;
|
||||||
|
@ -118,18 +118,20 @@ init(ConnInfo = #{peername := {PeerHost, _},
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
||||||
|
ConnInfo = ConnInfoT#{proto_name => <<"LwM2M">>, proto_ver => <<"0.0">>},
|
||||||
|
|
||||||
#channel{ ctx = Ctx
|
#channel{ ctx = Ctx
|
||||||
, conninfo = ConnInfo
|
, conninfo = ConnInfo
|
||||||
, clientinfo = ClientInfo
|
, clientinfo = ClientInfo
|
||||||
, timers = #{}
|
, timers = #{}
|
||||||
, session = emqx_lwm2m_session:new()
|
, session = emqx_lwm2m_session:new()
|
||||||
%% FIXME: don't store anonymouse func
|
%% FIXME: don't store anonymouse func
|
||||||
, with_context = with_context(Ctx, ClientInfo)
|
, with_context = with_context(Ctx, ClientInfo)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
with_context(Ctx, ClientInfo) ->
|
with_context(Ctx, ClientInfo) ->
|
||||||
fun(Type, Topic) ->
|
fun(Type, Topic) ->
|
||||||
with_context(Type, Topic, Ctx, ClientInfo)
|
with_context(Type, Topic, Ctx, ClientInfo)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
lookup_cmd(Channel, Path, Action) ->
|
lookup_cmd(Channel, Path, Action) ->
|
||||||
|
@ -293,7 +295,6 @@ check_lwm2m_version(#coap_message{options = Opts},
|
||||||
end,
|
end,
|
||||||
if IsValid ->
|
if IsValid ->
|
||||||
NConnInfo = ConnInfo#{ connected_at => erlang:system_time(millisecond)
|
NConnInfo = ConnInfo#{ connected_at => erlang:system_time(millisecond)
|
||||||
, proto_name => <<"LwM2M">>
|
|
||||||
, proto_ver => Ver
|
, proto_ver => Ver
|
||||||
},
|
},
|
||||||
{ok, Channel#channel{conninfo = NConnInfo}};
|
{ok, Channel#channel{conninfo = NConnInfo}};
|
||||||
|
|
Loading…
Reference in New Issue