<div dir="ltr">Dear list,<div>I am using cowboy to manage long-lived HTTP requests, that I use to send server generated events.</div><div><br></div><div>When a request comes in, I add it to a process registry. I can then send messages to the request process, that takes care of sending it down the TCP pipe.</div><div><br></div><div>The question is: when one of these processes dies, also because of an internal crash, I want to ensure that I remove it's pid from the process registry.</div><div><br></div><div>The question is: what is the best practice to do this? Is the terminate function called also when a process dies? If so, I could just do:</div><div><br></div><div><div><font face="monospace, monospace">init(_Type, Req, []) -><br></font></div><div><font face="monospace, monospace">    ets:insert(?PID_TABLE, {self()}),</font></div><div><font face="monospace, monospace">    {ok, Req, undefined}.</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">handle(Req, _ReqState) -></font></div><div><font face="monospace, monospace">    [handle request]</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">terminate(_Reason, _Req, _State) -></font></div><span style="font-family:monospace,monospace">    ets:delete(?PID_TABLE, {self()}),</span><div><font face="monospace, monospace">    ok.</font></div></div><div><br></div><div><br></div><div>Or do I need to monitor it with some kind of registry, for instance:</div><div><br></div><div><div><div><font face="monospace, monospace">init(_Type, Req, []) -><br></font></div><div><font face="monospace, monospace">    registry:register(self()),</font></div><div><font face="monospace, monospace">    {ok, Req, undefined}.</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">handle(Req, _ReqState) -></font></div><div><font face="monospace, monospace">    [handle request]</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">terminate(_Reason, _Req, _State) -></font></div><div><font face="monospace, monospace">    ok.</font></div></div></div><div><br></div><div><br></div><div>And <font face="monospace, monospace">registry</font> is a gen_server:</div><div><br></div><div><span style="font-family:monospace,monospace">register(Pid) -></span><br></div><div><span style="font-family:monospace,monospace">    </span><font face="monospace, monospace">gen_server:call(?MODULE,{register, Pid}).</font></div><div><br></div><div><font face="monospace, monospace">...</font></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">handle_call(</font><span style="font-family:monospace,monospace">{register, Pid}</span><font face="monospace, monospace">, _From, State) -></font></div><div><font face="monospace, monospace">    </font><span style="font-family:monospace,monospace">ets:insert(?PID_TABLE, {Pid}),</span></div><div><span style="font-family:monospace,monospace">    erlang:monitor(process, Pid),</span></div><div><font face="monospace, monospace">    {reply, ok, State};</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">...</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">handle_info({'DOWN', _Ref, process, Pid, _Reason}, State) -><br></font></div><div><font face="monospace, monospace">    ets:delete(?PID_TABLE, {Pid}),</font></div><div><font face="monospace, monospace">    {noreply, State}.</font></div><div><br></div><div><br></div><div>Any recommendations?</div><div><br></div><div>Thank you ^^_</div><div>r.</div><div><br></div></div>