[Twisted-Python] intermittent problem: not accepting new connections

Jean-Paul Calderone exarkun at divmod.com
Wed Sep 10 16:16:21 MDT 2008

On Wed, 10 Sep 2008 15:04:40 -0700, Alec Matusis <matusis at yahoo.com> wrote:
>> You could try running strace against the server while it's not
>> accepting
>> connections.
>I have one short question before I try strace on live:
>I have been playing with strace this morning on my dev, and I observe that for every second connection, there are two accept calls, one is success and one is a failure:

I'm pretty sure this is a consequence of a heuristic optimization in the
accept loop.  When one connection is successfully accepted, a counter is
incremented.  Whenever it tries to accept connections, it will try up to
the number of times indicated by the current value of the counter.  When
it fails to get a new connection, it drops the counter to the number of
connections it did accept.  So in a lot of cases, it's flipping back and
forth between 1 and 2 attempts.

The point of this is that if you're receiving lots of connection attempts,
it'd be faster to accept many of them at once instead of only accepting one
each time around the reactor loop.  It's not clear the current implementation
is the best way to implement this optimization, but at least the code is very
old and hasn't changed in quite a while, so it's probably not actually causing
any problems.


More information about the Twisted-Python mailing list