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

RJD-1495/fix #1511

Merged
merged 5 commits into from
Jan 28, 2025
Merged

RJD-1495/fix #1511

merged 5 commits into from
Jan 28, 2025

Conversation

robomic
Copy link
Contributor

@robomic robomic commented Jan 22, 2025

Abstract

This PR contains a bug fix for the issue described here.

Details

The reference to a value managed by the shared pointer escapes (Line 30).

namespace concealer
{
template <typename Message>
struct Subscriber
{
typename Message::ConstSharedPtr current_value = std::make_shared<const Message>();
typename rclcpp::Subscription<Message>::SharedPtr subscription;
auto operator()() const -> const auto & { return *std::atomic_load(&current_value); }
template <typename Autoware, typename Callback>
explicit Subscriber(
const std::string & topic, const rclcpp::QoS & quality_of_service, Autoware & autoware,
const Callback & callback)
: subscription(autoware.template create_subscription<Message>(
topic, quality_of_service,
[this, callback](const typename Message::ConstSharedPtr & message) {
if (std::atomic_store(&current_value, message); current_value) {
callback(*std::atomic_load(&current_value));
}
}))
{
}
template <typename Autoware>
explicit Subscriber(
const std::string & topic, const rclcpp::QoS & quality_of_service, Autoware & autoware)
: subscription(autoware.template create_subscription<Message>(
topic, quality_of_service, [this](const typename Message::ConstSharedPtr & message) {
std::atomic_store(&current_value, message);
}))
{
}
};
} // namespace concealer

When that const & is used and the underlying value is modified by the owner, a race condition occurs.
Return by value instead of by const & to force a copy and avoid the problem.

References

Regressions OK

@robomic robomic self-assigned this Jan 22, 2025
@robomic robomic added the bump patch If this pull request merged, bump patch version of the scenario_simulator_v2 label Jan 22, 2025
@robomic robomic marked this pull request as ready for review January 23, 2025 13:08
@yamacir-kit yamacir-kit merged commit 0ea9dd6 into master Jan 28, 2025
12 checks passed
@github-actions github-actions bot deleted the RJD-1495/fix branch January 28, 2025 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch If this pull request merged, bump patch version of the scenario_simulator_v2 wait for regression test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants