fix: Data race in new webserver (#1926)

There was a data race inside `CoroutineGroup` because internal timer was
used from multiple threads in the methods `asyncWait()` and
`onCoroutineComplete()`. Changing `registerForeign()` to spawn to the
same `yield_context` fixes the problem because now the timer is accessed
only from the same coroutine which has an internal strand.

During debugging I also added websocket support for `request_gun` tool.
This commit is contained in:
Sergey Kuznetsov
2025-02-27 15:08:46 +00:00
committed by GitHub
parent b909b8879d
commit d11e7bc60e
13 changed files with 116 additions and 32 deletions

View File

@@ -178,10 +178,10 @@ TEST_F(CoroutineGroupTests, SpawnForeign)
runSpawn([this](boost::asio::yield_context yield) {
CoroutineGroup group{yield, 1};
auto const onForeignComplete = group.registerForeign();
auto const onForeignComplete = group.registerForeign(yield);
[&]() { ASSERT_TRUE(onForeignComplete.has_value()); }();
[&]() { ASSERT_FALSE(group.registerForeign().has_value()); }();
[&]() { ASSERT_FALSE(group.registerForeign(yield).has_value()); }();
boost::asio::spawn(ctx_, [this, &onForeignComplete](boost::asio::yield_context innerYield) {
boost::asio::steady_timer timer{innerYield.get_executor(), std::chrono::milliseconds{2}};