This gist:
https://gist.github.com/jdeisenberg/5573843 is nearly the minimal code I could develop to demonstrate the problem. Here are the steps I used to duplicate the problem, with Erlang R16B (erts-5.10.1) and Interactive Elixir (
0.8.3.dev).
I have a Central server and multiple "Person" servers. A person can register her user name (and pid) with the Central server. Each Person also has a piece of information in his state. Person A can get person B's information by asking the server to retrieve it.
Open a terminal window and type:
iex --sname central
c("servertest.ex")
Central.start_link
Open a second terminal window and type:
iex --sname sales
Person.start_link("Spain")
:gen_server.call({Central, :central@localhost}, {:register, "Steve"})
Open a third terminal window and type:
iex --sname marketing
Person.start_link("Monaco")
:gen_server.call({Central, :central@localhost}, {:register, "Michele"})
Return to the first terminal. Explicitly call for Michele's info
by using a {Name, Node}:
:gen_server.call({Person, :marketing@localhost}, :get_info)
The response shows that marketing is listening.
Now go to the second terminal window (Steve in sales) and try
getting the information by sending Central a message to get Michele in marketing's info.
:gen_server.call({Central, :central@localhost}, {:info, "Michele"})
...and we get a timeout, but looking at the output from the central server, it seems that the PID for marketing is correct.
Central gets request from #PID<7777.32.0> to register Steve
Central gets request from #PID<7806.32.0> to register Michele
iex(central@localhost)2> :gen_server.call({Person, :marketing@localhost}, :get_info)
["Monaco"]
Central gets request for info about Michele from {#PID<7777.32.0>,#Reference<7777.0.0.75>}
Central sends info request to #PID<7806.32.0>
iex(central@localhost)3>
=ERROR REPORT==== 13-May-2013::22:04:06 ===
** Generic server 'Elixir-Central' terminating
** Last message in was {info,<<"Michele">>}
** When Server state == [{<<"Michele">>,<7806.32.0>},
{<<"Steve">>,<7777.32.0>}]
** Reason for termination ==
** {timeout,{gen_server,call,[<7806.32.0>,get_info]}}
In case you're wondering, "well why don't you just call via {module_name, node} instead of pid?" The reason is that there could be several Persons all using the same node, and the only way to get the person I want is by her unique pid.