fix: ensure cleanup after shutdown - #108
Merged
zmstone merged 3 commits intoNov 24, 2025
Merged
Conversation
zmstone
force-pushed
the
251122-ensure-cleanup-after-shutdown
branch
from
November 24, 2025 10:51
c117a35 to
59acb5d
Compare
thalesmg
approved these changes
Nov 24, 2025
Comment on lines
+204
to
+206
| handle_info({'EXIT', Pid, Reason}, #{owner := Pid} = St) -> | ||
| %% If owner is not supervisor | ||
| {stop, Reason, St}; |
Contributor
There was a problem hiding this comment.
This should not be possible in a gen_server, IIRC.
Indeed, a quick check indicates that's the case:
defmodule A do
use GenServer
def start_link() do
GenServer.start_link(__MODULE__, self())
end
def init(owner) do
Process.flag(:trap_exit, true)
{:ok, %{owner: owner}}
end
def handle_info({:EXIT, pid, reason}, %{owner: owner} = st) do
IO.inspect({owner, pid, reason})
{:noreply, st}
end
end
Process.flag(:trap_exit, true)
{:ok, pid0} = A.start_link()
# not the owner
spawn(fn -> Process.exit(pid0, :die_not_owner) end)
# owner tells it to die
Process.exit(pid0, :die_from_owner)Output (does not print inspect when exit signal comes from owner):
iex(5)> # not the owner
nil
iex(6)> spawn(fn -> Process.exit(pid0, :die_not_owner) end)
{#PID<0.105.0>, #PID<0.112.0>, :die_not_owner}
#PID<0.112.0>
iex(7)> # owner tells it to die
nil
iex(8)> Process.exit(pid0, :die_from_owner)
true
12:00:03.369 [error] GenServer #PID<0.111.0> terminating
** (stop) :die_from_owner
Last message: {:EXIT, #PID<0.105.0>, :die_from_owner}
State: %{owner: #PID<0.105.0>}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wolff_client_sup:ensure_absenceandwolff_producers_sup:ensure_absencewill perform shutdown and cleanup atomically.Previously, if the caller process is killed while waiting for shutdown, a terminated child may leak under the supervisor.
{Exit, Supervisor, shutdown}message get consumed, causingwolff_client_sup:ensure_absenceto force kill instead of normal shutdown.