angelikatyborska

angelikatyborska

GenServer start_link when stopped in init no longer returns a value in OTP 26?

I need advice as to whether this is a bug in OTP 26 (and where to report it?), or an expected change (is it listed in Otp 26.0 - Erlang/OTP ?)

I have a GenServer that can be stopped in its init callback like this:

defmodule StoppingServer do
  use GenServer

  @spec start_link(keyword()) :: {:ok, pid()} | {:error, atom()}
  def start_link(init_arg) do
    GenServer.start_link(__MODULE__, init_arg)
  end

  def init(_) do
    {:stop, :you_cant_start_me}
  end
end

When I call StoppingServer.start_link([]) with Elixir 1.15 or 1.14 and OTP 25, the call returns a value and then the process exits:

iex()> StoppingServer.start_link([])
{:error, :you_cant_start_me}
** (EXIT from #PID<0.108.0>) shell process exited with reason: :you_cant_start_me

However, when I use OTP 26, the process first exits. If I want to get the return value, I need to trap exits.

iex()> StoppingServer.start_link([])
** (EXIT from #PID<0.113.0>) shell process exited with reason: :you_cant_start_me

Interactive Elixir (1.15.0) - press Ctrl+C to exit (type h() ENTER for help)
iex()> Process.flag(:trap_exit, true)
false
iex()> StoppingServer.start_link([])
{:error, :you_cant_start_me}

Is that expected now? Does the Elixir documentation about GenServer need to be updated? The wording there suggests to me that the value will be returned first:

Returning {:stop, reason} will cause start_link/3 to return {:error, reason} and the process to exit with reason reason without entering the loop or calling terminate/2.

Most Liked

awerment

awerment

Seems like it was an intentional change in OTP 26.

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement