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

Use asio strands in udp channels #1880

Merged
merged 1 commit into from Apr 8, 2019

Conversation

2 participants
@cryptocode
Copy link
Collaborator

commented Apr 7, 2019

#1873 and #1876 fixed some issues in udp_channels (lock ordering causing load-tester to fail + tsan race reports), but they introduced another race.

Sockets are not thread safe and the recommended solution is to use strands.

Changes: Any access to the udp socket has to go through the strand, and bind_executor is used to also put the completion handler in the strand. This makes it safe to access the socket from the handler.

Using strands means no more calling socket.local_endpoint/is_open/close or async initiating functions directly - asio::post is used for this. This makes it a bit awkward to do calls like socket.local_endpoint(..) - as the caller would need a completion callback - so the local endpoint is put in a field in the constructor. The stop function then invalidates it (this keeps the endpoint_bad_fd test happy - previously it depended on socket being closed synchronously)

@cryptocode cryptocode added this to the V19.0 milestone Apr 7, 2019

@cryptocode cryptocode self-assigned this Apr 7, 2019

@cryptocode cryptocode requested a review from clemahieu Apr 7, 2019

@cryptocode cryptocode added this to CP3 (2019-04-10) in V19 Apr 7, 2019

@cryptocode cryptocode merged commit deee420 into nanocurrency:master Apr 8, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@cryptocode cryptocode deleted the cryptocode:udp/strands branch Apr 8, 2019

guilhermelawless added a commit to guilhermelawless/nano-node that referenced this pull request Apr 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.