fixeria submitted this change.
enb_registry: fix duplicate registration check in enb_register/0
next_handle was bound in the function head and reused in the case
pattern {ok, Handle}, turning what looks like a binding into an
equality test against next_handle. The duplicate check therefore
only fired if the previously assigned handle happened to equal the
current next_handle counter, which is essentially never true.
Fix by removing next_handle from the function head pattern and reading
it with S#state.next_handle inside the error branch, so that Handle in
{ok, Handle} is always a fresh binding that matches any existing handle.
Change-Id: Ia64f3e2e79bea055e5c37df9bce91a4bcbf7184c
---
M src/enb_registry.erl
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/enb_registry.erl b/src/enb_registry.erl
index d2487a0..29a2575 100644
--- a/src/enb_registry.erl
+++ b/src/enb_registry.erl
@@ -155,13 +155,13 @@
handle_call(enb_register,
{Pid, _Tag},
#state{enbs = ENBs,
- pids = PIDs,
- next_handle = Handle} = S) ->
+ pids = PIDs} = S) ->
case maps:find(Pid, PIDs) of
{ok, Handle} ->
?LOG_ERROR("eNB (handle=~p, pid=~p) is *already* registered", [Handle, Pid]),
{reply, {error, already_registered}, S};
error ->
+ Handle = S#state.next_handle,
%% keep an eye on the process being registered
MonRef = erlang:monitor(process, Pid),
%% create and store an initial eNB state
To view, visit change 42297. To unsubscribe, or for help writing mail filters, visit settings.