forked from aziomq/aziomq
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix leak of remaining pending operations during io_service destruction
Previously, ops were tracked in boost::intrusive::lists and deleted by unlinking from the list and calling do_complete, which did the "delete". However, any remaining ops in the queues during destruction of per_descriptor_data were not freed, because boost::intrusive::list destruction only unlinks and does not free the nodes. We need to free the reactor_ops remaining in the queue, but without calling the user-supplied completion handlers, because, for example, we want to prevent new enqueue() calls from coming in during io_service destruction. This matches boost::asio behaviour: "Uninvoked handler objects that were scheduled for deferred invocation on the io_context, or any associated strand, are destroyed." (https://www.boost.org/doc/libs/1_74_0/doc/html/boost_asio/reference/io_context/_io_context.html) Thus freeing needs to be separated from do_complete(). This patch refactors the op/queue memory management to fix the leak, and separates the memory management from the do_complete() action. Now, ops are tracked with std::deque + std::unique_ptr everywhere. They no longer delete themselves in do_complete(), but instead we rely on automatic destructor calls to free the memory. do_complete() calls are still done in the same place as before, but now they only call the completion handlers and leave the freeing to the destructors.
- Loading branch information
Showing
5 changed files
with
61 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters