tcp_close during async accept

Jim Morris <>
Thu Jul 9 01:16:15 CEST 2009


I doubt this is the problem, but I notice you both use tcp keep alive.
In the past this option has had issues in various TCP stacks, and if
my memory serves me correctly its use was frowned upon. That may be
old data, but I have been writing servers for many many years and have
never used that option.

I prefer to have the application protocol include some type of ping
that the client sends to the server every 30 seconds, this keeps any
intermediate NAT/Firewall box from losing the connection, and allows
the server to know when a client has vanished due to a cable unplug or
router going away (ie it never sees the FIN or RST). This works well
for HTTP long-poll type clients as well as proprietary clients.


On Jul 8, 3:17 pm, Steve Davis <> wrote:
> Joel et al.
>
> I'm not sure if this is related but I'm seeing the same thing about
> 30-50$ of the time on a client socket connection when using...
>
>   ok = inet:setopts(Socket, [{packet, http_bin}, {keepalive, true}]),
>   case gen_tcp:recv(Socket, 0, Timeout) of
>   ...
>
> ...possible bug in R13B01, or perhaps a bug in my usage of the socket?
>
> /sd
>
> On Jul 6, 11:20 am, Joel Reymont <> wrote:
>
>
>
> > I'm playing with Serge's "Non-blocking TCP server using OTP  
> > principles" [1]. When spawning a large number of connections almost at  
> > once, I'm seeing tcp_close messages on the client end, even before  
> > seeing inet_async on the client end.
>
> > I may spawn 700 client connections and only half may go through, even  
> > though my backlog option is 1024, e.g.
>
> >      Opts = [binary,
> >              {packet, 0},
> >              {reuseaddr, true},
> >              {keepalive, true},
> >              {backlog, 1024},
> >              {active, false}],
> >      case gen_tcp:listen(Port, Opts) of
> >          {ok, Socket} ->
> >              %% Create first accepting process
> >              {ok, Ref} = prim_inet:async_accept(Socket, -1),
> > ...
>
> > Any suggestions on what's going on?
>
> ________________________________________________________________
> erlang-questions mailing list. Seehttp://www.erlang.org/faq.html
> erlang-questions (at) erlang.org


More information about the erlang-questions mailing list