Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shards are being restarted while calling Phoenix.Tracker.graceful_permdown/1 #194

Open
tonnenpinguin opened this issue Mar 3, 2025 · 0 comments · May be fixed by #195
Open

Shards are being restarted while calling Phoenix.Tracker.graceful_permdown/1 #194

tonnenpinguin opened this issue Mar 3, 2025 · 0 comments · May be fixed by #195

Comments

@tonnenpinguin
Copy link

tonnenpinguin commented Mar 3, 2025

Hey all!

I noticed that when calling Phoenix.Tracker.graceful_permdown/1 shards are being restarted on the Tracker that we're currently in the process of shutting down.
Looking through the source code I think the problem ist that when we are passing the shards to the Supervisor, the child_spec field :restart defaults to :permanent which according to the Supervisor docs
means

  • :permanent - the child process is always restarted.

However, I think we actually want this:

  • :transient - the child process is restarted only if it terminates abnormally, i.e., with an exit reason other than :normal:shutdown, or {:shutdown, term}.

as in the Shard graceful_permdown callback we are trying to gracefully stop the Shard GenServer

  def handle_call(:graceful_permdown, _from, state) do
    broadcast_from(state, self(), {:pub, :graceful_permdown, Replica.ref(state.replica)})
    {:stop, :normal, :ok, state}
  end

Returning {:stop, reason, reply, new_state} stops the loop
https://hexdocs.pm/elixir/1.18.2/GenServer.html#c:handle_call/3

Explicitly specifying restart: :transient in https://github.com/phoenixframework/phoenix_pubsub/blob/main/lib/phoenix/tracker.ex#L328 seems to fix the issue.

Does that make sense? If yes, take a look at #195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant