[erlang-questions] Why does this crash?

Vimal Kumar vimal7370@REDACTED
Sun Sep 27 09:50:54 CEST 2015


Guess I found the answer:

1> bank_server:start_link().
{ok,<0.562.0>}

2> self().
<0.559.0>

3> exit(self(), kill).
** exception exit: killed

4> self().
<0.565.0>

5> whereis(bank_server).
undefined

Thank you!

On Sun, Sep 27, 2015 at 1:00 PM, Vimal Kumar <vimal7370@REDACTED> wrote:

> Hi all,
>
> Erlang newbie here. This is my first attempt to write an OTP module myself
> - a simple bank server. API functions allow users to register, login,
> deposit/withdraw money to/from their own account.
>
> The bank_server:login/2 function returns a secret key (sort of unique
> session id, lets assume) which is required for further meaningful
> transactions (like bank_server:deposit/3 or bank_server:withdraw/3).
>
> 1> bank_server:start_link().
> {ok,<0.549.0>}
>
> 2> whereis(bank_server).
> <0.549.0>
>
> 3> bank_server:new_user(user1, "mysecretpass1").
> {ok}
>
> 4> {_, SecretKey1} = bank_server:login(user1, "mysecretpass1").
> {ok,"lYWrBFIi7CoeYN8KSK3QgA=="}
>
> 5> bank_server:deposit(user1, SecretKey1, 10.00).
> {ok,success}
>
> 6> bank_server:check_balance(user1, SecretKey1).
> {ok,10.0}
>
> 7> bank_server:new_user(user2, "mysecretpass2").
> {ok}
>
> 8> {_, SecretKey1} = bank_server:login(user2, "mysecretpass2").
> ** exception error: no match of right hand side value {ok,
> "vYaWQbNQvROqXybVf424lQ=="}
>
> 9> whereis(bank_server).
> undefined
>
> In line 8, I understand that I should have used a different variable,
> since SecretKey1 already has a value. But I am curious why a simple mistake
> *** from client side *** crashed the server itself? Is there any way to
> avoid it?
>
> I am yet to learn OTP supervisors, but I believe it might have restarted
> the server without any delay in such a crash.
>
> The complete code for bank_server.erl is available at
> http://pastebin.com/4bMWjNG7 to check.
>
> Thank you!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150927/56f15922/attachment.htm>


More information about the erlang-questions mailing list