Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
watcher: Prevent busy wait if callback is active and other FDs have e…
…vents Exiting the loop previously could cause watcher to busy wait (i.e. rebuild the array and call poll() repeatedly) until the active callback was done. Assume watcher observes two FDs 15 and 22, which are in the list in that order. FD 15 is signaled and its callback gets triggered. The array of FDs is rebuilt and does not include 15 anymore. Now FD 22 is ready for reading. However, when enumerating all registered FDs, the loop previously was exited when reaching FD 15 and seeing that it's active. FD 22 was never checked and the array was immediately rebuilt and poll() called. If the callback for 15 took longer, this was repeated over and over. This basically reverts d16d5a2 ("watcher: Avoid queueing multiple watcher callbacks at the same time"), whose goal is quite unclear to me. If it really wanted to allow only a single callback for all FDs, it didn't achieve that as any FD before an active one would get notified and if multiple FDs are ready concurrently, they'd all get triggered too. Skipping entries with active callback makes sense as it avoids a lookup in the FD array and subsequent revents checks. But why would we need to rebuild the array if we see such an entry? Once the callback is done, the watcher is notified and the array rebuilt anyway (also if any other FD was ready and jobs get queued).
- Loading branch information