Erlang: robustness against port owner's death
Asked Answered
T

1

6

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?

Thaumatrope answered 8/11, 2010 at 20:9 Comment(0)
Q
5

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

Quit answered 9/11, 2010 at 0:25 Comment(4)
I don't think the port sends a special message to the spawned process, and I don't see this in the documentation you link to. What will happen is that the pipe to the process is closed and this you can catch in the process itself (e.g. lookout for eof on your input)Decapolis
But have also to say that I absolutly agree with your first paragraphDecapolis
I am sorry, but you are wrong. Table 14.3 lists as the last message exit reasons. You can also call link/1 on a port to link to it if you will. Also, notice that to get this message, your process must be trapping exit signals via process_flag/2, or otherwise it wont work.Quit
I think you are talking of different things here. Peer is describing how the external port process sees that the port has been closed (eof on its input pipe) while NOT CRAPPY ANSWERS is describing the how the connected erlang process sees it.Backwoods

© 2022 - 2024 — McMap. All rights reserved.