Skip to content

Commit bd2c141

Browse files
authored
fix: Fix GenRpc to not try to connect to nodes that are not alive (#1525)
1 parent da3404a commit bd2c141

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/realtime/gen_rpc.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ defmodule Realtime.GenRpc do
4141
@spec call(node, module, atom, list(any), keyword()) :: result
4242
def call(node, mod, func, args, opts)
4343
when is_atom(node) and is_atom(mod) and is_atom(func) and is_list(args) and is_list(opts) do
44+
if node == node() or node in Node.list() do
45+
do_call(node, mod, func, args, opts)
46+
else
47+
tenant_id = Keyword.get(opts, :tenant_id)
48+
49+
log_error(
50+
"ErrorOnRpcCall",
51+
%{target: node, mod: mod, func: func, error: :badnode},
52+
project: tenant_id,
53+
external_id: tenant_id
54+
)
55+
56+
{:error, :rpc_error, :badnode}
57+
end
58+
end
59+
60+
defp do_call(node, mod, func, args, opts) do
4461
timeout = Keyword.get(opts, :timeout, default_rpc_timeout())
4562
tenant_id = Keyword.get(opts, :tenant_id)
4663
key = Keyword.get(opts, :key, nil)

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
44
def project do
55
[
66
app: :realtime,
7-
version: "2.47.0",
7+
version: "2.47.1",
88
elixir: "~> 1.17.3",
99
elixirc_paths: elixirc_paths(Mix.env()),
1010
start_permanent: Mix.env() == :prod,

test/realtime/gen_rpc_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ defmodule Realtime.GenRpcTest do
172172
mechanism: :gen_rpc
173173
}}
174174
end
175+
176+
test "bad node" do
177+
178+
179+
log =
180+
capture_log(fn ->
181+
assert GenRpc.call(node, Map, :fetch, [%{a: 1}, :a], tenant_id: 123) == {:error, :rpc_error, :badnode}
182+
end)
183+
184+
assert log =~
185+
~r/project=123 external_id=123 \[error\] ErrorOnRpcCall: %{+error: :badnode, mod: Map, func: :fetch, target: :"#{node}"/
186+
end
175187
end
176188

177189
describe "multicast/4" do

0 commit comments

Comments
 (0)