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

On MSVC 2017, segfaults occur in test 37 #25

Open
andreasbuhr opened this issue Dec 6, 2020 · 1 comment · May be fixed by #33
Open

On MSVC 2017, segfaults occur in test 37 #25

andreasbuhr opened this issue Dec 6, 2020 · 1 comment · May be fixed by #33

Comments

@andreasbuhr
Copy link
Owner

In:
https://github.com/andreasbuhr/cppcoro/runs/1505811235?check_suite_focus=true

we see
The following tests FAILED:
37 - async auto reset event tests-multi-threaded (SEGFAULT)

wich happens sometimes.

@karzhenkov
Copy link

karzhenkov commented Jan 7, 2021

It seems that the crash occurs due to a stack overflow in startWaiter lambda function. Coroutines awaiting on the async_auto_reset_event are sometimes resumed inside a call to set(), which is a documented behavior. There are multiple coroutines created by startWaiter, so the chain of nested continuations may become too long.

auto startWaiter = [&]() -> cppcoro::task<>
{
co_await tp.schedule();
co_await event;
++value;
event.set();
};

With a slightly modified startWaiter it is possible to detect nested continuations.

(see code)
	std::atomic<int> depth = 0;

	auto startWaiter = [&]() -> cppcoro::task<>
	{
		co_await tp.schedule();
		co_await event;
		++value;
		int d = depth++;
		assert(d < 3); // if depth is greater than number of threads in the pool,
		               // this is executed as a nested continuation
		event.set();
		depth -= 1;
	};

Interestingly, when there is only one thread in the thread pool, the test completes successfully.

@karzhenkov karzhenkov linked a pull request Jan 10, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants