T0ha666
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.
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
:warning: Security advisory: Decimal DoS vulnerability
A vulnerability has been published for decimal where very large exponents can cau...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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.
T0ha666
Supervisor works in the same manner.
LostKobrakai
Are you trying to start a supervisor or trying to use one already running? The first option will have the exact same constraints I just described for the genserver. It doesn’t matter what process you start, if you use rpc you don’t want to link the started process to the rpc code executing process.
Not linking processes is however not a great thing to do, as they won’t be properly shut down when the system shuts down. So really the genserver (or other processes) should be linked to a supervisor in one of the supervision trees on that other node instead of being linked to the rpc code executing process.
T0ha666
I’m trying to write UnitTest for distributed code. If there is another way I’m curious about it.
LostKobrakai
I described two options on how to resolve the problems you’re having.
:peeris certainly the way to test things requiring distribution.T0ha666
:peer.call/4works in the same manner.LostKobrakai
It doesn’t matter how many layers you put over
:rpc. The issue isn’t the method of transfering the code to be called to the other node. The issue is in the code you let it execute.schneebyte
There is also
:erlang.spawn_linkOr implement
start/1for your GenServer and use:erpc.call.Or put your GenServer under a Supervisor and start your application on the peer node.