Performing a lookup in a non-existent scope will result in missing all existing scopes.
mohsenmoqadam opened this issue · comments
Hello, dears.
I am using version 3.3.0
. Suppose we add node to a scope like this: syn:add_node_to_scopes([users])
and register a process like this:
Pid = self().
syn:register(users, "hedy", Pid).
If I then call syn:lookup
with a non-existent scope name like this:
syn:lookup(sers, "hedy").
I will get this error:
** exception error: {invalid_scope,sers}
in function syn_registry:lookup/2 (_build/default/lib/syn/src/syn_registry.erl, line 76)
If I call syn:lookup
with an existing scope like this:
syn:lookup(users, "hedy").
I will get undefined
. If I try to register Pid
again, I will get the following error:
{error,not_alive}
Can you help me understand what is incorrect? Also, why is it that if we perform a lookup in a non-existent scope, all existing scopes will be missed?
Calling syn with a non-existant scope will result in an error.
When an error happens in a console, the console thread is killed and it is replaced with a new one.
Now consider these two points and follow what you are doing. First, you register the console process. Then, you call syn:lookup(sers, "hedy").
, an action that raises an error which causes that console process to die. Since the process died, it gets unregistered. The process in Pid
is now dead.
Therefore, when you now call syn:lookup(users, "hedy").
you get undefined
because, well, the original console process died. Same when you try to register Pid
again: it is dead. You cannot register a dead process.
If you don't understand, just print out the value of self()
after every operation and you'll see that it changes.
Thank you for your complete and helpful explanations. Best of luck to you🙏❤️