Skip to content

Commit

Permalink
fix: Fix registry alive call (#2048)
Browse files Browse the repository at this point in the history
Ensures that we can hold connections when electric is not ready even if
it is not started (useful in multi tenant)
  • Loading branch information
msfstef authored Nov 26, 2024
1 parent 4e50204 commit ceec2d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-shoes-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@core/sync-service": patch
---

Assume process is not alive if registry is not alive.
4 changes: 4 additions & 0 deletions packages/sync-service/lib/electric/process_registry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ defmodule Electric.ProcessRegistry do
nil -> false
_ -> true
end
rescue
# if the registry is not started, whereis will raise - we can
# assume that the process is not alive
ArgumentError -> false
end
end
23 changes: 23 additions & 0 deletions packages/sync-service/test/electric/process_registry_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule Electric.ProcessRegistryTest do
use ExUnit.Case, async: true
alias Electric.ProcessRegistry

@stack_id "foo"

describe "alive?/2" do
test "should return false for inexistent process" do
{:ok, _} =
ProcessRegistry.start_link(
name: ProcessRegistry.registry_name(@stack_id),
keys: :duplicate,
stack_id: @stack_id
)

assert false == ProcessRegistry.alive?(@stack_id, "bar")
end

test "should return false for any process if registry not started" do
assert false == ProcessRegistry.alive?(@stack_id, "bar")
end
end
end

0 comments on commit ceec2d4

Please sign in to comment.