[erlang-questions] Why does this crash?

Vimal Kumar <>
Sun Sep 27 12:28:16 CEST 2015


Hi Jesper,

I now implemented supervision trees along with the application controller,
and things now work as it should be.

1> application:start(mybank).
ok

2> whereis(bank_server).
<0.38.0>

3> bank_server:new_user(user1, "d3fault").
{ok}

4> {_, UniqueId} = bank_server:login(user1, "d3fault").
{ok,"OsNTJVIQgyb9ERHg3q9SLg=="}

5> bank_server:new_user(user2, "d3fault").
{ok}

6> {_, UniqueId} = bank_server:login(user2, "d3fault").
** exception error: no match of right hand side value {ok,
"w7MJ1HQrHIDbVlNOh5bSpg=="}

7> whereis(bank_server).
<0.38.0>

Unlinking the process is a great tip for testing from shell, didn't cross
my mind.

Thanks!

On Sun, Sep 27, 2015 at 3:24 PM, Jesper Louis Andersen <
> wrote:

>
> On Sun, Sep 27, 2015 at 10:52 AM, Vimal Kumar <> wrote:
>
>> Going to add supervisors into this system and learn more about it.
>
>
> It doesn't happen in real systems, because the supervision trees are
> linked to the application controller, and not the shell. If you simply add
> a supervision tree, and link that tree to the shell, you are usually not
> free of the problem.
>
> When developing however, you can unlink the pid:
>
> {ok, P} = foo:start_link().
> unlink(P).
>
> which will have P not die if the shell does.
>
> The other resources to look out for are ETS tables, and port()'s, that is
> network sockets and files. If their controlling process, i.e. the shell,
> goes away, then that resource is cleaned/reaped/closed again.
>
>
> --
> J.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150927/1c524f1a/attachment.html>


More information about the erlang-questions mailing list