Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mdns-avahi] handle freed AvahiWatch/Timeout entries as processing run loop #2019

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

abtink
Copy link
Member

@abtink abtink commented Sep 15, 2023

Avahi provides a mechanism to integrate it to a select() style run loop where an implementation can provide an AvahiWatch and an AvahiTimeout structure along with a set of related APIs (as function pointers given to Avahi client) for it to allocate new watch/timeout entries or update or free them. A watch entry provides a set of events to watch for and expects its given callback to be invoked when the events occur. A timeout provides an abstraction for a timer.

This commit updates AvahiPoller (which integrates Avahi to run loop as a MainloopProcessor) to protect against situations where entries get freed or updated as Avahi callbacks are invoked from AvahiPoller::Process().

When we invoke the callback for an AvahiWatch or AvahiTimeout the Avahi module can call any of APIs we provided to it. For example, it can update or free any existing AvahiWatch/Timeout entry, which in turn, modifies the mWatches or mTimers list being tracked by the AvahiPoller.

This commit updates the AvahiPoller class to correctly handle such situations. Before invoking the callback, we update the entry's state and after returning from callback we restart the iteration over the watch/timer list to find the next entry to report, as the list may have changed during execution of the callback.

Copy link
Contributor

@superwhd superwhd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

…run loop

Avahi provides a mechanism to integrate it to a `select()` style run
loop where an implementation can provide an `AvahiWatch` and an
`AvahiTimeout` structure along with a set of related APIs (as
function pointers given to Avahi client) for it to allocate new
watch/timeout entries or update or free them. A watch entry provides
a set of events to watch for and expects its given callback to be
invoked when the events occur. A timeout provides an abstraction for
a timer.

This commit updates `AvahiPoller` (which integrates Avahi to run loop
as a `MainloopProcessor`) to protect against situations where entries
get freed or updated as Avahi callbacks are invoked from
`AvahiPoller::Process()`.

When we invoke the callback for an `AvahiWatch` or `AvahiTimeout` the
Avahi module can call any of APIs we provided to it. For example, it
can update or free any existing `AvahiWatch/Timeout` entry, which in
turn, modifies the `mWatches` or `mTimers` list being tracked by the
`AvahiPoller`.

This commit updates the `AvahiPoller` class to correctly handle such
situations. Before invoking the callback, we update the entry's state
and after returning from callback we restart the iteration over the
watch/timer list to find the next entry to report, as the list may
have changed during execution of the callback.
@jwhui jwhui merged commit 1576ade into openthread:main Sep 20, 2023
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants