From 19e607e486c24eb317633b794df72249e91c0c6e Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Wed, 10 Jun 2026 16:12:35 +0200 Subject: [PATCH] test: fix racy loop-variable capture in SubscriptionThreadSafety - the subscriber threads captured the loop counter by reference while the spawning loop kept incrementing it: a genuine data race - depending on timing, threads could also end up with duplicate subscriber names; capture the counter by value instead --- test/plugin_services/_control.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plugin_services/_control.cxx b/test/plugin_services/_control.cxx index 498c44a8..ebe8e9ee 100644 --- a/test/plugin_services/_control.cxx +++ b/test/plugin_services/_control.cxx @@ -156,7 +156,7 @@ TEST_F(PluginServices, SubscriptionThreadSafety) std::array, subscribers> threads; auto id = 0; for (auto& thread : threads) { - thread = std::make_unique([&](){ + thread = std::make_unique([&, id](){ auto const subscriber = fair::mq::tools::ToString("subscriber_", id); for (auto i = 0; i < attempts; ++i) { mServices.SubscribeToDeviceStateChange(subscriber, [](DeviceState){});