Making accept() not block

Aaron Hopkins lists at die.net
Sun May 14 05:35:30 UTC 2006


Oh, I didn't notice it since my select()-reduction patch makes UDP sockets
non-blocking, but this race condition is present for UDP in NSD 2.3.4 as
well if -N is > 1.

The sequence would go something like:

1) Both processes select().

2) select() in both processes shows data to read on the same UDP socket, so
    both processes recvfrom().

3) recvfrom() in one socket gets the new packet, while the other process
    blocks until the next packet is available on that socket.

If you have more than one UDP socket open (multiple -a flags passed) and are
blocking on a socket that is very infrequently used, this could result in
all but one child process being unable to answer requests.  If you are on a
multi-processor machine, this would cause a significant reduction of NSD's
peak throughput on that machine.

The fix is straightforward: If you are going to be using select() or similar
for multiplexing, all network sockets you might pass to it need to be marked
as non-blocking.

                                     -- Aaron



More information about the nsd-users mailing list