X gen_server also died when monitored Y gen_server died. why?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

X gen_server also died when monitored Y gen_server died. why?

I Gusti Ngurah Oka Prinarjaya
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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: X gen_server also died when monitored Y gen_server died. why?

Alin Popa
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 <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: X gen_server also died when monitored Y gen_server died. why?

I Gusti Ngurah Oka Prinarjaya
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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: X gen_server also died when monitored Y gen_server died. why?

Alin Popa
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: X gen_server also died when monitored Y gen_server died. why?

I Gusti Ngurah Oka Prinarjaya
Hi,

It's ok.. i will try another way. i think it must be under a supervisor.

Thank you 

Pada tanggal Sen, 3 Jun 2019 15.52, Alin Popa <[hidden email]> menulis:
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: X gen_server also died when monitored Y gen_server died. why?

I Gusti Ngurah Oka Prinarjaya
Hi,

Solved!. Yes i run a X supervisor process, run a X gen_server process as adjoining process / sibling process with X supervisor process.
Then under X supervisor i add / run P1, P2, P3 gen_server process, and each process under X supervisor is monitored by X gen_server process.
and it works!

Thank you


Pada tanggal Sen, 3 Jun 2019 pukul 19.06 I Gusti Ngurah Oka Prinarjaya <[hidden email]> menulis:
Hi,

It's ok.. i will try another way. i think it must be under a supervisor.

Thank you 

Pada tanggal Sen, 3 Jun 2019 15.52, Alin Popa <[hidden email]> menulis:
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions