T0ha666

T0ha666

Unexpected :slave.call/4 or :peer.call/4 behaviour

Hi.
I have a simple GenServer module like:

defmodule TestGenServer do
  @moduledoc false

  use GenServer

  def start_link(options), do: GenServer.start_link(__MODULE__, options, name: __MODULE__)

  @impl true
  def init(_options) do
    IO.inspect("INIT")
    {:ok, %{}, 0}
  end

  def fetch(), do: GenServer.call(__MODULE__, :fetch)

  @impl true
  def handle_call(:fetch, _from, state) do
    reply = :ok
    {:reply, reply, state}
  end

  @impl true
  def handle_info(:timeout, state) do
    IO.inspect("Timeout")
    {:noreply, state, 100}
  end
end

I’m trying to start it on other or slave node like.

Node.start(:'test@127.0.0.1')
pa = :code.get_path |> Enum.reduce([], &([~c"-pa", &1 | &2]))
{:ok, pid, node} = :peer.start_link(%{name: :test1, host: ~c"127.0.0.1", args: pa})
{:ok, p} = :rpc.call(node, TestGenServer, :start_link, [:ok])
:rpc.call(node, TestGenServer, :fetch, [])

And last call fails with

{:badrpc, {:EXIT, {:noproc, {GenServer, :call, [TelemetryMetricsMnesia, :fetch, 5000]}}}}

If I use :rpc.cast/4 to start GenServer everything works fine.

Is it expected behaviour for :npc.call/4 to terminate process after it returns?
I tried on Erlang 26.1.2 with Elixir 1.15.7 and Erlang 26.0.2 with Elixir 1.15.4. Both works in the same manner.

First Post!

LostKobrakai

LostKobrakai

RPC afaik works by having a process on the other node execute your code. That process starts and links your genserver. Then the process executing your code stops, so the genserver stops as well, as it was linked to that process.

Cast might work by accident if the process executing the first cast has not been stopped / and brought down the genserver before the call is executed.

You either want to start the genserver without linking it to the caller process or even better start it as a child of some supervisor running on the other node.

Where Next?

Popular in Discussions Top

PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
MarioFlach
Hello, I want to share a project I’ve been working on for a while: https://github.com/almightycouch/gitgud Background Some time ago I ...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
slashdotdash
Phoenix Live View is now publicly available on GitHub. Here’s Chris McCord’s tweet announcing making it public.
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New

We're in Beta

About us Mission Statement