gen_tcp:recv() and client_machine_crash

Yani Dzhurov <>
Tue Jun 27 12:36:03 CEST 2006


Hi,

Why don't trying using the keep alive option for tcp socket:

{keepalive, Boolean} (TCP/IP sockets) 
Enables/disables periodic transmission on a connected socket, when no other
data is being exchanged. If the other end does not respond, the connection
is considered broken and an error message will be sent to the controlling
process. Default disabled.

This is from the inet module docs . I think this should work for you.

Cheerz,

Jani

-----Original Message-----
From: 
[mailto:] On Behalf Of HP Wei
Sent: Monday, June 26, 2006 10:15 PM
To: 
Subject: gen_tcp:recv() and client_machine_crash


I have a server (written in Erlang) which handles
clients' request(s) through tcp_socket by
the following piece of psudo-code:

handle_request(Sock) ->
   case gen_tcp:recv(Sock, 0) of
     {ok, Bin} ->
         handle_Bin(...);
     {error, Reason} ->
         handle_exit(...)
   end.

[ Note: The client code is written in python. ]

I want the handle_exit() to handle three abnormal-exit situations
that may occur on the client side.
(1) the client's code gets Control_C exit;
(2) the client's code gets killed by 'kill -9 pid'
    [ under UNIX ];
(3) the machine that the client is running on
    crashes !

For (1) and (2), the part 'handle_exit()' in the
above snippet gets executed as expected.

However, we had a client_machine_crash this morning
but the handle_exit(..) did not seem to get executed.

Questions:
   Is it supposed to be executed ?
   If yes, I will check the other part of the server-code.
   If no, then what is the proper way to detect a
   machine crash ??

thanks
HP

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3326 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060627/0e30b629/attachment.bin>


More information about the erlang-questions mailing list