scottyscripts

scottyscripts

Background

I am running a distributed Elixir (Phoenix) application.

I want to run one instance of a globally registered GenServer for all my n nodes. (thinking singleton coming from OO). This process is under a supervision tree in my app.

The start_link function in my GenServer looks like:

 def start_link(_opts \\ []) do 
    GenServer.start_link(__MODULE__, [], name: {:global, __MODULE__})
  end

When I start my GenServer, I’m successfully seeing it registered globally and running.
If I try to run my GenServer on a connected node, I get an error as expected.

Problem

(assuming I’m running 2 nodes)
When the app is started, it looks like the GenServer process is being started on Node A and B. One of those nodes joins the cluster. Then when the other node joins the cluster, I am getting an error as expected based on the erlang :global docs

from global — OTP 29.0.2 (kernel 11.0.2) -

When new nodes are added to the network, they are informed of the globally registered names that already exist. The network is also informed of any global names in newly connected nodes. If any name clashes are discovered, function Resolve is called. Its purpose is to decide which pid is correct. If the function crashes, or returns anything other than one of the pids, the name is unregistered. This function is called once for each name clash.

What I Want To Do

I would like to handle this error.
I have tried trapping exits in my GenServer’s init function by adding Process.flag(:trap_exit, true)

But realized that the default Resolve function to handle these name clashes sends a kill message to a process (which I don’t think I can trap)

I noticed that one of the other Resolve functions would allow me to handle this error

When registering the GenServer globally in start_link, is there any way to specify the Resolve callback used in case of a name clash?

Showing Posts 1 to 1

scottyscripts

scottyscripts OP

So I don’t think what I’m trying to do is possible (or via the way I’m trying to do it)

Options specified in GenServer’s start_link function, are eventually passed to erlang’s :gen.start
https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/gen_server.ex#L922

according to gen_server — OTP 29.0.2 (stdlib 8.0.1),

If ServerName={global,GlobalName}, the gen_server process id registered globally as GlobalName using global:register_name/2 If no name is provided, the gen_server process is not registered.

global:register_name/2 does not provide the option to specify the Resolve callback as global:register_name/3 does (global — OTP 29.0.2 (kernel 11.0.2))

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews