cullan (3) [Avatar] Offline
#1
I checked out the code from the git repository, compiled it, and started the tcp_rpc application with application:start(tcp_rpc). After that I tried to use the get_count/0 function in the tr_server module.

> application:start(tcp_rpc).
ok

> tr_server:get_count().
** exception exit: {timeout,{gen_server,call,[tr_server,get_count]}}
in function gen_server:call/2 (gen_server.erl, line 180)

I used appmon and pman I noticed that the tr_server process receives messages that look like {'$gen_call', {<0.32.0>, #Ref<0.0.0.108>}, get_count}. They seem to keep accumulating if I continue to try to call get_count/0. When I traced the tr_server process, it showed that it received the messages but it never called the handle_call/3 function as expected. I modified the handle_call function to accept any kind of message and reply with the server state but it is never called.

Any ideas?
richard.carlsson (66) [Avatar] Offline
#2
Re: problem with get_count in chapter 4
At a quick glance, I'd say that the tr_server process is stuck somewhere (otherwise messages wouldn't be accumulating). Can you see the current function of the process?
cullan (3) [Avatar] Offline
#3
Re: problem with get_count in chapter 4
The current function is {prim_inet, accept0,2}
richard.carlsson (66) [Avatar] Offline
#4
Re: problem with get_count in chapter 4
Ah, of course. The first thing that server wants to do is accept a TCP connection, before it will handle any requests. (See page 113.)

If you connect via telnet first, you should be able to use get_count afterwards.
cullan (3) [Avatar] Offline
#5
Re: problem with get_count in chapter 4
Aha. I understand now. Thank you.
douglasv (316) [Avatar] Offline
#6
Re: problem with get_count in chapter 4
It seems we are talking to erl and not tr_server process?

Escape character is '^]'.
lists:reverse([1,2,3]).
[3,2,1]

init:stop().
ok
Connection closed by foreign host.

tr_server:get_count().
{timeout,{gen_server,call,[tr_server,get_count]}}
Connection closed by foreign host.

=ERROR REPORT==== 13-Mar-2012::10:18:49 ===
** Generic server tr_server terminating
** Last message in was {#Ref<0.0.0.37>,{ok,3}}
** When Server state == {state,1055,#Port<0.522>,3}
** Reason for termination ==
** {function_clause,[{tr_server,handle_info,
[{#Ref<0.0.0.37>,{ok,3}},
{state,1055,#Port<0.522>,3}]},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]}

=INFO REPORT==== 13-Mar-2012::10:18:49 ===
application: tcp_rpc
exited: shutdown
type: temporary
richard.carlsson (66) [Avatar] Offline
#7
Re: problem with get_count in chapter 4
You're talking to the tr_server process, but if you ask it to call init:stop(), then that will shut down the whole node. Erlang has no built-in way of checking privileges, so any process is allowed do anything, including writing to the file system. We warn about this at the bottom of page 116.
431592 (1) [Avatar] Offline
#8
I am a little confused about the calling of get_count.
How is it done using the telnet connection, or is that even possible?

> tr_server:get_count(). works fine from the erlang shell the app is running in. But I have not found a way thru the Telent session to call the get_count(), the same way I called intit:stop();

Is there a way to call the get_count through the telnet connection?