[erlang-questions] gen_tcp server won't release sockets?

Keith Irwin keith.irwin@REDACTED
Tue Apr 21 17:42:46 CEST 2009


Folks--
I've implemented a gen_tcp server based on the example at the end of the
gen_tcp man page. In other words, it spawns 5 processes for a process pool.
Each process blocks on an accept call to a listen socket, reads an incoming
request, responds with a response, then loops around to block on the accept
again.

The thing is, each of these processes in the process pool seems to hold a
link to a port, as in, <#Port 0.123> (or something like that). I know this
because I can start up the appmon, click on the process in the pool, and see
an ever growing list of Ports inside the { links } tuple.

When a certain limit is reached, I get an "enfile" or "emfile" error, the
process dies, the ports (or whatever they are), are reclaimed. I then
spawn_link a new process to add to the pool, and off I go.

Is there some reason a process which loops over an "gen_tcp:accept" would
keep holding on to the connections it gets in its link table?

Another wrinkle: I'm running the gen_tcp server from within a gen_server
instance. The gen_service:init creates the listen socket, then spawns the
process pool (via spawn_link). I use handle_info to trap a call to EXIT to
spawn a new process pool instance if one of the existing ones dies.

(Mac OSX 10.5.6, Erlang R12B-5 via MacPorts)

Keith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090421/1c352f60/attachment.htm>


More information about the erlang-questions mailing list