[mdns]: Prevent deadlock when deleting a browse request (IDFGH-13947) #676
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
With v1.3.0 the mDNS component supports continuous browsing for services by calling
mdns_browse_new()
. In v1.4.0 whenever one wants to stop browsing for a specific service viamdns_browse_delete()
there is a deadlock resulting in underlying mdns task to block forever, caused by the API locking introduced with the "Fix API race" commits for v1.4.0.Background:
API requests are generally serialized into the mdns task - this also applies to the
mdns_browse_...
calls. The request to stop browsing for a service is put into the mdns task queue and is actually handled by the task via_mdns_execute_action()
->_mdns_browse_finish()
. There it performs a linear search through the queue of pending browse requests to find a matching mDNS service/protocol tuple. Upon match it deletes the item via_mdns_browse_item_free()
what callsmdns_query_results_free()
. The latter is a public API call that tries to acquire the lock semaphore. Unfortunately the initial call to_mdns_execute_action()
in the mdns task is already within a locked section. So in result themdns_query_results_free()
method waits endlessly for the semaphore getting released.Checklist
Before submitting a Pull Request, please ensure the following:
Documentation is updated as needed.(no functional change)Tests are updated or added as necessary.(no functional change)