Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performing a lookup in a non-existent scope will result in missing all existing scopes. #76

Closed
mohsenmoqadam opened this issue Apr 9, 2023 · 2 comments
Labels

Comments

@mohsenmoqadam
Copy link

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?

@ostinelli
Copy link
Owner

ostinelli commented Apr 10, 2023

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.

@mohsenmoqadam
Copy link
Author

Thank you for your complete and helpful explanations. Best of luck to you🙏❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants