priestjim / gen_rpc

A scalable RPC library for Erlang-VM based languages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gen_rpc:call(OtherNode, erlang, node, []) always return self.

goofansu opened this issue · comments

(gate@127.0.0.1)1> gen_rpc:call('b@127.0.0.1', erlang, node, []).
16:04:47.228 [info] event=client_process_not_found server_node="b@127.0.0.1" action=spawning_client
16:04:47.228 [info] event=initializing_client node="b@127.0.0.1"
16:04:47.231 [warning] lager_error_logger_h dropped 67 messages in the last second that exceeded the limit of 50 messages/sec
16:04:47.243 [info] event=client_connection_received client_ip="127.0.0.1:50443" socket="#Port<0.12095>" action=starting_acceptor
16:04:47.251 [info] event=listener_started_successfully peer="127.0.0.1:50443"
16:04:47.251 [info] event=client_connection_received peer="127.0.0.1:50443" socket="#Port<0.12250>" action=starting_acceptor
16:04:47.251 [info] event=start peer="127.0.0.1:50443"
'gate@127.0.0.1'
(gate@127.0.0.1)2> net_adm:world().
['b@127.0.0.1','gate@127.0.0.1']

I added a remote test and an integration test (you can run integration tests if you have docker in your $PATH) and they both succeed. What version are you using?

would also be helpful to change the lager flag to debug, and then post the trace log here.

I'm using version 1.0.2.

rebar.config

{erl_opts, [debug_info]}.
{deps, [{gen_rpc, "1.0.2"}]}.

Start other_node:

~ ❯❯❯ erl -name other_node@127.0.0.1
Erlang/OTP 18 [erts-7.2.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V7.2.1  (abort with ^G)
(other_node@127.0.0.1)1>

Start my_app:

~/w/mylib ❯❯❯ rebar3 shell --name my_app@127.0.0.1                                     ⏎
===> Verifying dependencies...
===> Compiling mylib
Erlang/OTP 18 [erts-7.2.1] [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false] [dtrace]

Eshell V7.2.1  (abort with ^G)
(my_app@127.0.0.1)1> lager:start().
ok
(my_app@127.0.0.1)2> 15:04:28.211 [info] Application lager started on node 'my_app@127.0.0.1'
(my_app@127.0.0.1)2> application:start(gen_rpc).
15:04:36.833 [info] event=start
15:04:36.836 [info] event=listener_started_successfully port="5369"
15:04:36.837 [info] Application gen_rpc started on node 'my_app@127.0.0.1'
ok
(my_app@127.0.0.1)3> gen_rpc:call('other_node@127.0.0.1', erlang, node, []).
15:06:33.885 [info] event=client_process_not_found server_node="other_node@127.0.0.1" action=spawning_client
15:06:33.885 [info] event=initializing_client node="other_node@127.0.0.1"
15:06:33.904 [info] event=client_connection_received client_ip="127.0.0.1:50512" socket="#Port<0.11628>" action=starting_acceptor
15:06:33.912 [info] event=listener_started_successfully peer="127.0.0.1:50512"
15:06:33.913 [info] event=client_connection_received peer="127.0.0.1:50512" socket="#Port<0.11667>" action=starting_acceptor
15:06:33.913 [info] event=start peer="127.0.0.1:50512"
'my_app@127.0.0.1'
(my_app@127.0.0.1)4> rpc:call('other_node@127.0.0.1', erlang, node, []).
'other_node@127.0.0.1'

This is not a bug. You are starting a node with gen_rpc and one without. gen_rpc cannot have 2 nodes running on the same system (without configuring a different listener port) so when you're trying to connect to the other remote-"local" node, internally gen_rpc resolves the IP on the right side of the node name and connects to the listener port there. Since in this case the IP is 127.0.0.1, it connects to itself and hence it returns its own node name. If you had launched the other_node with gen_rpc as well, make shell would have crashed with {error, eaddrinuse} because of the TCP listener port clash.

@priestjim Thank you. Can I deploy it with two nodes on one machine?

I've read remote_tcp_server_ports but wonder is it relative to this question?

Yes you can. Let's say you have node1@localhost and node2@localhost. Set node1 configuration to

    {tcp_server_port, 5369},
    {remote_tcp_server_ports, [{'node2@localhost', 5370}]}

And node2 configuration to:

    {tcp_server_port, 5370},
    {remote_tcp_server_ports, [{'node1@localhost', 5369}]}

It should work transparently!

@priestjim Sorry for the late.

I created file node1.config:

[{gen_rpc, [    
        {tcp_server_port, 5369},
        {remote_tcp_server_ports, [{'node2@localhost', 5370}]}
    ]
}].

and node2.config

[{gen_rpc, [    
        {tcp_server_port, 5370},
        {remote_tcp_server_ports, [{'node2@localhost', 5369}]}
    ]
}].

Start with rebar3 shell --name=node1@127.0.0.1 --config node1 and rebar3 shell --name=node2@127.0.0.1 --config node2, but both are listening at 5369, so I can only start one node.

15:19:54.951 [info] Application lager started on node 'node2@127.0.0.1'
15:19:54.956 [info] event=start
15:19:54.959 [info] event=listener_started_successfully port="5369"
===> Booted syntax_tools
15:19:54.960 [info] Application gen_rpc started on node 'node2@127.0.0.1'

You're supposed to start the shell with --config node1.config!

Got it. Sorry for the trouble. Thanks