1. Fred T-H
  2. chut


Fred T-H  committed 371d6d0

Fixing errors when sending messages to disconnected users

In the previous versions of chut, sending messages to a user was
done through {global, User}. This made it so messages sent to
undefined users would simply fail silently and gen_event:notify/2
would return 'ok'.

By changing the registration to work outside of the gen_* mechanisms,
a lookup with global:whereis_name/1 was done. In the case of an
invalid name, the function returns undefined. This, in turn, generates
an error when sending in local mode, because the Erlang VM tries to
find a process locally registered to the atom 'undefined'.

This fix makes it so the call will silently fail like it used to, as
it was the desired behavior.

  • Participants
  • Parent commits bbc77f5
  • Branches default

Comments (0)

Files changed (1)

File src/chut_user_manager.erl

View file
  • Ignore whitespace
 %% Description: Sends the Event through the event manager.
 notify(UserId, Message) ->
-    Pid = global:whereis_name({manager, UserId}),
-    gen_event:notify(Pid, Message).
+    case global:whereis_name({manager, UserId}) of
+        undefined -> ok; % fail silently like with {global, Name}.
+        Pid -> gen_event:notify(Pid, Message)
+    end.