Hmm. Actually I think when I was writing that code I noticed the same
thing and tried to fix it with:

                /* there can be multiple events for a single io.
                   call the callback only once if that happens. */
                if (io->refcount == 2 && io->io.callback != NULL)
                        io->io.callback(io->io.context);

When there are near-duplicates in the returned events -- that is, two or more entries in the events array having the same udata but different fflags -- the refcount==2 check actually prevents the callback from being called at all (assuming Apple's patch to this area has not been applied, and the assert is removed). The first loop increments the refcount twice (or more), from 1 to 3 (or higher). Then the second loop skips the callback entirely because the refcount does not equal 2. The callback is not even called once.

I think it would work correctly simply if the assert was removed?

Removing the assert would cause the callback to be called twice (or more). Probably not good. I know the O(n^2) algorithm to find and remove duplicates is undesirable but in practice n is small.

Reply via email to