[zeromq-dev] Potential bug in select

Steven McCoy steven.mccoy at miru.hk
Wed Jan 27 16:32:53 CET 2016

On 27 January 2016 at 10:15, Ilya Kulakov <kulakov.ilya at gmail.com> wrote:

> Hi,
> I found the following 2 chunks of code suspecting:
> - https://github.com/zeromq/libzmq/blob/master/src/select.cpp#L110-L113
> - https://github.com/zeromq/libzmq/blob/master/src/select.cpp#L170-L173
> Why do we need to clear descriptos, if readfds/writefds/exceptfds are
> initialized with contents of source_set_* at each iteration of the loop?
> It may lead to an error if set is modified _while_ there is an active
> select in another thread (I don't know if an instance of select_t can be
> used from multiple threads).
> Other than that this code looks pointless.
> What do you think?

Standard fair is that one event can cause the API to remove the socket from
the set before one iteration of the loop has finished.


Of note there is actually a double check with L209-210.

If you can guarantee the file descriptor is moved to retired_fd then you
can remove the removal from the descriptor set.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20160127/dc9c3f41/attachment.htm>

More information about the zeromq-dev mailing list