]> git.ipfire.org Git - thirdparty/strongswan.git/commit
watcher: Prevent busy wait if callback is active and other FDs have events
authorTobias Brunner <tobias@strongswan.org>
Tue, 18 Apr 2023 16:18:48 +0000 (18:18 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 27 Apr 2023 11:52:34 +0000 (13:52 +0200)
commit30803f90eb3721db178822bca203fb14696cfced
tree324c4f59a36ec4a2640d6c4267e0efbaebc09648
parent53208b0ba4c17f6efc9df3007ecf9626471fd78d
watcher: Prevent busy wait if callback is active and other FDs have events

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 d16d5a245f0b ("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).
src/libstrongswan/processing/watcher.c