-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mcap] Fix destructor race condition (#94)
Since the writer was help outside of the subscribers (which are in different threads), there is a race on delete to delete the subscribers before they attempt to write new messages via the closing writer. To solve this, we allow the subscribers to hold the writer together in a shared_ptr. We also hold the data for the subscriber in a shared_ptr, although after construction the subscriber holds the only ref. We also solve the issue of the subscriber needing a callback which is self referential by filling in a weak_ptr after construction. The previous approach relied on construction completing before the first message is received. While this race condition probably wouldn't have been realized (subscriber construction is rather fast), we guard against it anyway, especially as the user can try to create any number of subscribers, so the first subscriber may have received a message before the overall writer had completed construction. Each subscriber is now self-contained, and does not rely on the overall class being constructed, which is now just a wrapper around a vector of subscribers. While we're here add a number of missing moves. We also have to increment the ecal version in this PR, as ecal was missing proper subscriber destructor handling, which led to race conditions and sometimes getting `pure virtual method called`.
- Loading branch information
Showing
9 changed files
with
124 additions
and
133 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
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