Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang: robustness against port owner's death

What happens when the process which owns a spawned port dies and is restarted by the supervisor?

  1. Is there a way for the old port not to die with its owner and for the new owner to "take over"?

  2. Failing that, is it possible to ensure that the spawned process terminates when its port dies?

like image 836
Alexey Romanov Avatar asked Nov 08 '10 20:11

Alexey Romanov


1 Answers

First, notice that you don't want the port owner to die. So move any "dangerous" code out to another process and make the port owner as dumb as possible. This is error-mitigation the Erlang way. Now, if that process dies, something is really bad, so in that case it may be clever to recycle the port as well. But since we moved everything out, we are counting on that not happening.

Regarding 2, the port will send a specific message when it terminates, so you can arrange for your spawned process to gracefully detect this and terminate with it. See

http://www.erlang.org/doc/reference_manual/ports.html

like image 73
I GIVE CRAP ANSWERS Avatar answered Oct 12 '22 03:10

I GIVE CRAP ANSWERS