rpc/erpc behaviour

133 views
Skip to first unread message

Bogdan Andu

unread,
Feb 25, 2022, 3:56:16 AM2/25/22
to Erlang
Hello,

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
:erpc.send_request/wait_response.

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.

Cheers,

Bogdan


Michał Muskała

unread,
Feb 25, 2022, 4:26:33 AM2/25/22
to Bogdan Andu, Erlang

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.

 

Michał.

Bogdan Andu

unread,
Feb 25, 2022, 5:29:34 AM2/25/22
to Michał Muskała, Erlang
Bassically, it is a call to SomeMonitor.monitor(action)
which calls this:
GenServer.call(sm, {:monitor, action})
which calls this:
def handle_call({:monitor, action}, {pid, _ref}, state) do
    ref = Process.monitor(pid)

    emit(%{module: __MODULE__, name: :monitor, metadata: %{monitored_action: action}})

    {:reply, :ok, state}
  end.

in a GenServer named process started by an application's  supervisor.

Bogdan
Reply all
Reply to author
Forward
0 new messages