What happens when the process which owns a spawned port dies and is restarted by the supervisor?
Is there a way for the old port not to die with its owner and for the new owner to "take over"?
Failing that, is it possible to ensure that the spawned process terminates when its port dies?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With