Skip to content

Commit

Permalink
Issue #597: Fix crash when a handler is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
gotthardp committed Feb 15, 2019
1 parent 01307db commit 4cf0212
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/lorawan_admin_connections.erl
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ content_types_accepted(Req, State) ->

handle_action(Req, #state{app=App, action = <<"send">>}=State) ->
case lorawan_backend_factory:nodes_with_backend(App) of
[#node{devaddr=DevAddr, appargs=AppArgs}=Node|_] ->
[{Profile, #node{devaddr=DevAddr, appargs=AppArgs}=Node}|_] ->
Vars = #{
event => <<"test">>,
app => App,
devaddr => DevAddr,
appargs => AppArgs,
datetime => calendar:universal_time()},
lager:debug("Sending connector test ~p to ~p", [App, lorawan_utils:binary_to_hex(DevAddr)]),
lorawan_backend_factory:event(App, {lorawan_db:get_profile(Node), Node}, Vars);
lorawan_backend_factory:event(App, {Profile, Node}, Vars);
[] ->
lager:debug("Connector not linked with any node")
end,
Expand Down
4 changes: 2 additions & 2 deletions src/lorawan_application_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ send_downlink(Handler, #{app := AppID}, undefined, TxData) ->
% downlink to a group
filter_group_responses(AppID,
lists:map(
fun(#node{devaddr=DevAddr}=Node) ->
fun({_Profile, #node{devaddr=DevAddr}=Node}) ->
purge_frames(Handler, Node, TxData),
lorawan_application:store_frame(DevAddr, TxData)
end,
Expand All @@ -263,7 +263,7 @@ send_downlink(Handler, #{app := AppID}, Time, TxData) ->
% class C downlink to a group of devices
filter_group_responses(AppID,
lists:map(
fun(Node) ->
fun({_Profile, Node}) ->
try_class_c(Handler, Node, Time, TxData)
end,
lorawan_backend_factory:nodes_with_backend(AppID)));
Expand Down
9 changes: 6 additions & 3 deletions src/lorawan_backend_factory.erl
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ announce_backend_update(App) ->

nodes_with_backend(App) ->
lists:foldl(
fun(#profile{name=ProfId}, Acc) ->
Nodes = mnesia:dirty_index_read(node, ProfId, #node.profile),
Acc ++ Nodes
fun(#profile{name=ProfId}=Profile, Acc) ->
lists:foldl(
fun(Node, Acc2) ->
[{Profile, Node} | Acc2]
end,
Acc, mnesia:dirty_index_read(node, ProfId, #node.profile))
end,
[], mnesia:dirty_index_read(profile, App, #profile.app)).

Expand Down

0 comments on commit 4cf0212

Please sign in to comment.