fixeria submitted this change.

View Change

Approvals: osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve fixeria: Looks good to me, approved
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.

Gerrit-MessageType: merged
Gerrit-Project: erlang/osmo-s1gw
Gerrit-Branch: master
Gerrit-Change-Id: Ia64f3e2e79bea055e5c37df9bce91a4bcbf7184c
Gerrit-Change-Number: 42297
Gerrit-PatchSet: 2
Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>