Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_
insideasync_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 ifcancel
on socket is threadsafe (I assume it's not) but to avoid similar problems shouldn'tstrand
be used for a singleasio_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.