[erlang-questions] Simple tcp server
Jesper Louis Andersen
Sun Jan 16 20:23:07 CET 2011
On Sun, Jan 16, 2011 at 19:02, Kaiduan Xie <> wrote:
> The gen_server is the controlling process of the listen socket, when
> you terminate the gen_server, the gen_tcp:accept(Socket) will return
> error with reason closed, and it goes endless loop in your accept()
> process, so your CPU hits 97-100%.
> You can catch [error, closed} for gen_tcp:accept(), and close the listen socket.
An additional problem is that each accepted socket is controlled by
the spawned acceptor process. So if it decides to die, all your
sockets will be gone (A socket is automatically closed when its
controlling process dies). You should, in time, consider moving the
controller so it is controlled by the right process.
More information about the erlang-questions