[erlang-questions] can "gen_tcp:recv" blocks my entire server?

Roberto Ostinelli roberto@REDACTED
Thu Apr 22 11:06:25 CEST 2010


>>> On Apr 21, 2010, at 6:16 PM, "zabrane Mikael"<zabrane3@REDACTED>
>>> wrote:
>>>> My question is simple. If one of my child processes calls
>>>> gen_tcp:recv/2 and
>>>> blocks (due to a slow client),
>>>> does this also blocks all other spawned childs?
>>>>
>>>> If yes, what's the best way to read from a socket without blocking the
>>>> entire server (i.e the other spawned processes)?

this shouldn't be the case. that's one of the main reasons why it is a
common pattern to spawn a process for every accepted socket. there's
most probably something wrong somewhere in your server design.


2010/4/22 Mazen Harake <mazen.harake@REDACTED>:
> Have you looked into {active,once} ? I think it is more suitable in your
> case. My suggestion would be to open an accepted socket with {active,
> false}, then setopts(Sock,[{active, once}]) when you are ready to receive
> the request (in your code) and then handle that and go back to
> setopts(Sock,[{active,once}]) every time you want to get a packet in your
> code.

pardon me, why shouldn't it be {active, once} from the beginning? just curious..

r.


More information about the erlang-questions mailing list