<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-GB" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Is the sub-process started with spawn_link?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">RPC can start a new process to evaluate the function, which might terminate as soon as it’s finished. If the spawned process is linked to this short-lived RPC process, the spawned process will be
also terminated through link propagation.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">From the rpc:call documentation:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">> You cannot make <b>any</b> assumptions about the process that will perform the apply(). It may be the calling process itself, an rpc server, another server, or a freshly spawned process.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Micha³.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">erlang-questions <erlang-questions-bounces@erlang.org> on behalf of Bogdan Andu <bog495@gmail.com><br>
<b>Date: </b>Friday, 25 February 2022 at 08:56<br>
<b>To: </b>Erlang <erlang-questions@erlang.org><br>
<b>Subject: </b>rpc/erpc behaviour<o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal">Hello,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">While working with rpc and erpc call and cast I noticed<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">a strange behaviour and I don't know if this is intended or not.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Basically, a call to a Module.function on a local node, :'node1', creates a process sub-tree that stays alive as expected.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">However if the same cal to Module.function is performed from a remote node<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">with a rpc or erpc call from ;'node2':<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">(node2)> :rpc.cast(:'node1', Elixir.Module, :function, [args])
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">the process sub-tree created by Module.function on :'node1' dies .<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I have tried every variant: :rpc.cast/call, :erpc.cast/call, even
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">:erpc.send_request/wait_response.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Those calls are made from between nodes running as Elixir nodes.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Nodes are Erlang 24 and Elixir 1.12.2 (:'node2') and Elixir 1.13.0 (:'node1')<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">The solution I founded is to use a Genserver which apparently keeps the
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">process sub-tree alive.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Is it normal that rpc calls cast ro call to end the function on the remote node even if it has the side effects of starting process sub-tree?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Why is that happening? Is that normal?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">From the manual page:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="https://www.erlang.org/doc/man/rpc.html#call-5">https://www.erlang.org/doc/man/rpc.html#call-5</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">"... It is used for collecting information on a remote node, or for running a function with some
<b>specific side effects </b>on the remote node."<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Those side effects would mean in my case that the process sub-tree to remain alive to use that as a service<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">but then again, that side effect disappears once the :rpc.cast/call ends.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I made a little test:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I put a :timer.sleep(10_000) at the end of Module.function<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">and for 10 seconds the process sub-tree is alive, after that it is killed as<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">the function invoked remotely ends.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I want to invoke that function as a library call, not as a GenServer call.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">How can I do that?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I want to wrap in GenServer locally the rpc calls to remote node function as a library call.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Bogdan<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>