rpc/erpc behaviour

Bogdan Andu bog495@REDACTED
Fri Feb 25 11:29:09 CET 2022


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

On Fri, Feb 25, 2022 at 11:26 AM Michał Muskała <michal@REDACTED> wrote:

> 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ł.
>
>
>
> *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
>
> 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:
>
> https://www.erlang.org/doc/man/rpc.html#call-5
>
> "... 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
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20220225/6f85bb07/attachment.htm>


More information about the erlang-questions mailing list