Skip to content

Backport !1713 “gmain: g_main_context_check() can skip updating polled FD sources” to glib-2-66

If there is a file descriptor source that has a lower priority than the one for sources that are going to be dispatched, all subsequent file descriptor sources (internally sorted by file descriptor identifier) do not get an update in their GPollRec and later on wrong sources can be dispatched.

Fix this by first finding the first GPollRec that matches the current GPollFD, instead of relying on it to be the current one. At the same time, document the assumptions about the ordering of the file descriptor records and array and make explicit in the documentation that the array needs to be passed to g_main_context_check() as it was received from g_main_context_query().

Added a new test that reproduces the bug by creating two file descriptor sources and an idle one. Since the first file descriptor created has a lower identifier and a low priority, the second one is not dispatched even when it has the same, higher, priority as the idle source. After fixing this bug, both higher priority sources are dispatched as expected.

While this patch was written independently, a similar fix for this bug was first submitted by Eugene M in !562 (closed). Having a second fix that basically does the same is a reassurance that we are in the right here.

Fixes #1592 (closed)


Trivial backport of !1713 (merged) to glib-2-66.

Merge request reports