Fri Feb 25 10:26:20 CET 2022
Is the sub-process started with spawn_link?
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.
>From the rpc:call documentation:
> You cannot make any 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.
From: erlang-questions <erlang-questions-bounces@REDACTED> on behalf of Bogdan Andu <bog495@REDACTED>
Date: Friday, 25 February 2022 at 08:56
To: Erlang <erlang-questions@REDACTED>
Subject: rpc/erpc behaviour
While working with rpc and erpc call and cast I noticed
a strange behaviour and I don't know if this is intended or not.
Basically, a call to a Module.function on a local node, :'node1', creates a process sub-tree that stays alive as expected.
However if the same cal to Module.function is performed from a remote node
with a rpc or erpc call from ;'node2':
(node2)> :rpc.cast(:'node1', Elixir.Module, :function, [args])
the process sub-tree created by Module.function on :'node1' dies .
I have tried every variant: :rpc.cast/call, :erpc.cast/call, even
Those calls are made from between nodes running as Elixir nodes.
Nodes are Erlang 24 and Elixir 1.12.2 (:'node2') and Elixir 1.13.0 (:'node1')
The solution I founded is to use a Genserver which apparently keeps the
process sub-tree alive.
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?
Why is that happening? Is that normal?
>From the manual page:
"... It is used for collecting information on a remote node, or for running a function with some specific side effects on the remote node."
Those side effects would mean in my case that the process sub-tree to remain alive to use that as a service
but then again, that side effect disappears once the :rpc.cast/call ends.
I made a little test:
I put a :timer.sleep(10_000) at the end of Module.function
and for 10 seconds the process sub-tree is alive, after that it is killed as
the function invoked remotely ends.
I want to invoke that function as a library call, not as a GenServer call.
How can I do that?
I want to wrap in GenServer locally the rpc calls to remote node function as a library call.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions