lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

It was thus said that the Great William Ahern once stated:
> On Thu, Dec 11, 2014 at 12:31:28PM -0500, Sean Conner wrote:
> > It was thus said that the Great Valerio Schiavoni once stated:
> > > 
> > > Due to continuous 'timeout' errors returned by the receiving socket (which
> > > is set to nonblocking, socket:settimeout(0)), the coroutine continuosly
> > > yields: in this case, is the reception of the data somehow put 'on hold' ?
> > 
> >   You don't need to set the socket to non-blocking if you use select just
> > for reading (and I just checked our codebase at work---I don't set any of
> > the sockets to nonblocking).  All select() does is indicate when a file
> > descriptor (in your case, a network socket) has received data (ready for
> > reading), can write data without blocking (ready for writing [1]) or an
> > error happened.
> This is not true at all, and people who assume this are running code with
> TOCTTOU bugs. Spurious wakeups can be very common. There are two common
> scenarios.
> 1) Two threads reading from the same socket. Both get woken up, one drains
> the socket, the other ends up stalled. This is easy to avoid, but proves the
> point about the semantics of readiness notification. It applies equally to
> writability as to readability.

  No true for Linux any more (this is the "thundering herd" problem).  Now,
only one thread/process is woken up---the one that actually received the

> Another poor assumption people make is thinking they don't need to set UDP
> sockets to non-blocking when writing, or even bother with polling for write
> readiness. Because UDP is lossy they assume that the kernel will simply drop
> any packet that won't fit in the output queue, immediately returning control
> to the writing thread. Not true, at least not on Linux. OTOH, Linux as a
> default socket buffer size of 65536 which means, again, you only trigger
> this bug under very heavy UDP load.

  I'm not sure what distribution you are using, but I'm still running a
2.6.9 kernel (32b) at home, and it reports a default UDP buffer size of
110592; at work I'm running Linux 3.2.0 (64b) and it reports a default UDP
buffer size of 229376.