• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / realtime / 4f4c2229d7a9f5c93b72feb5ca63ba86a8664ee5-PR-1363

07 May 2025 08:26PM UTC coverage: 82.791% (+0.7%) from 82.079%
4f4c2229d7a9f5c93b72feb5ca63ba86a8664ee5-PR-1363

Pull #1363

github

filipecabaco
adjust gh actions
Pull Request #1363: fix: handle regionless state in syn & non found process on register_process

7 of 10 new or added lines in 4 files covered. (70.0%)

6 existing lines in 2 files now uncovered.

1756 of 2121 relevant lines covered (82.79%)

1571.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/lib/realtime/syn_handler.ex
1
defmodule Realtime.SynHandler do
2
  @moduledoc """
3
  Custom defined Syn's callbacks
4
  """
5
  require Logger
6
  alias RealtimeWeb.Endpoint
7

8
  @doc """
9
  When processes registered with :syn are unregistered, either manually or by stopping, this
10
  callback is invoked.
11

12
  Other processes can subscribe to these events via PubSub to respond to them.
13

14
  We want to log conflict resolutions to know when more than one process on the cluster
15
  was started, and subsequently stopped because :syn handled the conflict.
16
  """
17
  def on_process_unregistered(mod, name, _pid, _meta, reason) do
18
    case reason do
119✔
19
      :syn_conflict_resolution ->
20
        Logger.warning("#{mod} terminated: #{inspect(name)} #{node()}")
1✔
21

22
      _ ->
23
        topic = topic(mod)
118✔
24
        Endpoint.local_broadcast(topic <> ":" <> name, topic <> "_down", nil)
118✔
25
    end
26

27
    :ok
28
  end
29

30
  def resolve_registry_conflict(mod, name, process1, process2) do
31
    [{keep, _, _}, {stop, _, _}] = Enum.sort_by([process1, process2], &elem(&1, 2))
1✔
32

33
    if node() == node(stop),
1✔
34
      do: spawn(fn -> resolve_conflict(mod, stop, name) end),
1✔
NEW
35
      else: Logger.warning("Resolving #{name} conflict, remote pid: #{inspect(stop)}")
×
36

37
    keep
1✔
38
  end
39

40
  defp resolve_conflict(mod, stop, name) do
41
    resp =
1✔
42
      if Process.alive?(stop) do
×
43
        try do
1✔
44
          Process.exit(stop, :shutdown)
1✔
45
        catch
46
          error, reason -> {:error, {error, reason}}
×
47
        end
48
      else
49
        :not_alive
50
      end
51

52
    topic = topic(mod)
1✔
53
    Endpoint.broadcast(topic <> ":" <> name, topic <> "_down", nil)
1✔
54

55
    Logger.warning("Resolving #{name} conflict, stop local pid: #{inspect(stop)}, response: #{inspect(resp)}")
1✔
56
  end
57

58
  defp topic(mod) do
59
    mod
60
    |> Macro.underscore()
61
    |> String.split("/")
62
    |> Enum.take(-1)
63
    |> hd()
119✔
64
  end
65
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc