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

supabase / realtime / c5c8f617a3ad63a2c3506a1b61ecd513ebad1ed3

07 May 2025 08:44PM UTC coverage: 82.461% (+0.4%) from 82.079%
c5c8f617a3ad63a2c3506a1b61ecd513ebad1ed3

push

github

web-flow
fix: remove region from syn conflict handling & non found process on register_process (#1363)

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

8 existing lines in 3 files now uncovered.

1749 of 2121 relevant lines covered (82.46%)

1349.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
122✔
19
      :syn_conflict_resolution ->
20
        Logger.warning("#{mod} terminated: #{inspect(name)} #{node()}")
1✔
21

22
      _ ->
23
        topic = topic(mod)
121✔
24
        Endpoint.local_broadcast(topic <> ":" <> name, topic <> "_down", nil)
121✔
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()
122✔
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

© 2025 Coveralls, Inc