[erlang-questions] X gen_server also died when monitored Y gen_server died. why?

Alin Popa alin.popa@REDACTED
Mon Jun 3 10:51:34 CEST 2019


Looks like since you're doing the stop through the gen_server:call, you'll
need to return {stop, Reason, Reply, State}, and in your code I can see
you're doing {stop, Reason, State}.
Now, why is this happening, I don't know.

Alin

On Mon, Jun 3, 2019 at 1:18 AM I Gusti Ngurah Oka Prinarjaya <
okaprinarjaya@REDACTED> wrote:

> Hi,
>
> I've use process_flag(trap_exit, true) in X:init() but still failed. X
> still died. mmm.. if i look closely to the error message, the erlang shell
> is also died
>
>
> Thank you
>
>
>
> Pada tanggal Sen, 3 Jun 2019 pukul 02.53 Alin Popa <alin.popa@REDACTED>
> menulis:
>
>> Looks like you've linked the Y process to the X process, therefore when Y
>> exists it'll take down X as well.
>> What you could do is to make process X to trap exit:
>>
>> ```
>> process_flat(trap_exit, true)
>> ```
>>
>> Usually you could add that within the `init` function of process X.
>> When you do that, if any linked process exists, it'll send a message to
>> the process X instead of taking it down.
>>
>> Hope that helps,
>> Alin
>>
>> On Sun, Jun 2, 2019 at 7:01 PM I Gusti Ngurah Oka Prinarjaya <
>> okaprinarjaya@REDACTED> wrote:
>>
>>> Hi,
>>>
>>> I create two gen_server. Let's say X gen_server, and Y gen_server.
>>>
>>> X gen_server do monitoring using erlang:monitor/2 to Y gen_server.
>>> When i do Y:stop(). X gen_server also died.
>>>
>>> I want to *X gen_server still alive* even monitored Y gen_server is
>>> died.
>>>
>>> This is X gen_server https://pastebin.com/G2xDNxMf
>>> This is Y gen_server https://pastebin.com/hWUfUPmn
>>>
>>> This is the result when i run my code
>>>
>>> 1> oka_oprek_agensrv:start_link().
>>>
>>> {ok,<0.86.0>}
>>>
>>> 2> oka_oprek_agensrv:start_bgensrv().
>>>
>>> {ok,start_bgensrv,
>>>
>>>     {<0.84.0>,#Ref<0.1555235413.310640643.180158>}}
>>>
>>> 3> oka_oprek_agensrv:hello().
>>>
>>> {ok,hello,{<0.84.0>,#Ref<0.1555235413.310640643.180166>}}
>>>
>>> 4> oka_oprek_bgensrv:hello().
>>>
>>> {ok,hello_from_b,
>>>
>>>     {<0.84.0>,#Ref<0.1555235413.310640643.180173>}}
>>>
>>> 5> oka_oprek_bgensrv:stop().
>>>
>>> Monitored process died. Ref=#Ref<0.1555235413.310640643.180161>,
>>> Pid=<0.88.0>
>>>
>>> ** exception exit: {normal,{gen_server,call,[bgensrv,stop]}}
>>>
>>>      in function  gen_server:call/2 (gen_server.erl, line 215)
>>>
>>> 6> oka_oprek_agensrv:hello().
>>>
>>> ** exception exit: {noproc,{gen_server,call,[agensrv,hello]}}
>>>
>>>      in function  gen_server:call/2 (gen_server.erl, line 215)
>>>
>>> 7>
>>>
>>>
>>> Please enlightenment
>>>
>>>
>>>
>>> Thank you
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190603/035d6cf5/attachment.htm>


More information about the erlang-questions mailing list