简体   繁体   中英

Erlang: rpc:call to remote node crashes with function_clause

So I searched around a bit and found that I could use rpc:call/5 to ask a remote node if it got a process registered under a certain name and timeout if the node couldn't be reached, however whenever I try to call rpc:call/5 with the following params:

Pid = rpc:call(Node, erlang, whereis, [Name], 3000)

It just crashes and I can't figure out which of the param(s) are causing it. The following crash had the params: 'Node=name@0.0.0.0' and 'Name=server'

** Reason for termination ==
** "{{function_clause,[{gen,call,[{rex,\"name@0.0.0.0\"},'$gen_call',
{call,erlang,whereis,[\"server\"],<0.24.0>},3000],
[{file,\"gen.erl\"},{line,149}]},{gen_server,call,3,[{file,\"gen_server.erl\"},{line,186}]},
{rpc,'-do_call/3-fun-0-',4,[{file,\"rpc.erl\"},{line,344}]}]},
{gen_server,call,[{rex,\"name@0.0.0.0\"},
{call,erlang,whereis,[\"server\"],<0.24.0>},3000]}}"
12> ** exception error: "{{function_clause,[{gen,call,\n
[{rex,\"name@0.0.0.0\"},'$gen_call',{call,erlang,whereis,[\"server\"],<0.24.0>},3000],
[{file,\"gen.erl\"},{line,149}]},
{gen_server,call,3,[{file,\"gen_server.erl\"},{line,186}]},
{rpc,'-do_call/3-fun-0-',4,[{file,\"rpc.erl\"},{line,344}]}]},\n {gen_server,call,
[{rex,\"name@0.0.0.0\"},{call,erlang,whereis,[\"server\"],<0.24.0>},3000]}}"

The node 'name@0.0.0.0' doesn't exist but if that was the problem shouldn't it return with a timeout after 3 seconds?

It looks like you're passing the node name as a string, but rpc:call expects an atom. (And likewise for the argument to whereis , by the way.)

Try this:

Pid = rpc:call(list_to_atom(Node), erlang, whereis, [list_to_atom(Name)], 3000)

Or alternatively, pass the arguments as atoms to begin with. server can be passed as is, but name@0.0.0.0 needs to be quoted, since it contains periods. Atoms are quoted with single quotes:

Node = 'name@0.0.0.0'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM