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

Fix data race in asio service #556

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

antonio2368
Copy link
Contributor

We detected a data race with one of our tests
https://pastila.nl/?0003c12b/68530aca8742766996176fdebcede8dc#KBCq01QCyL4Qz2lDbsNzrA==

It's insanely hard to parse all that asio stacktrace but the race happens on operation_timer_ inside async_resolve callback.
My theory is that async_connect got resolved and had its callback called before we setup the timer and started it.
So the problem should be solved with moving timer setup before we start the async_connect.

Now for the general issue.
Asio in NuRaft is run with a single io context on multiple threads. This can lead to data races in general (e.g. timer calls socket.cancel()). I'm not sure if cancel on socket is threadsafe (I assume it's not) but to avoid similar problems shouldn't strand be used for a single asio_rpc_client?
If you think I misunderstood something or there is a simpler solution, I'm open for discussion.
If not, I can introduce strand for the client.

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 this pull request may close these issues.

1 participant