Page MenuHomePhabricator

Fix race condition when reading from the network in mininode.py
ClosedPublic

Authored by deadalnix on Jun 28 2017, 12:03.

Details

Summary

In some rare cases, a test would fail memtionning that it got an invalid message. This could be reproduced consistently on tests that use heavily the network such as abc-p2p-fullblocktest.py when choosing a small read buffer size (in my case 8). By inspecting the data read from the network, it appeared that blocks of 8 bytes were swapped in these invlid messages.

This is dead giveaway that the buffer pieces are reassembled in an invalid order.

In order to prevent this from happening, we take a the lock on the node when recieving data from the network. in order to avoid too much contention, the decoded message is returned from got_data instead and got_message is called after the lock was freed.

Test Plan

Reduce the value of READ_BUFFER_SIZE to 8

  • Ensure some tests are failing consistently withotu that patch
  • Ensure these tests pass consistently with that patch

Run the whole qa test suite in order to ensure nothing was broken inadvertently.

../qa/pull-tester/rpc-tests.py -extended

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

deadalnix created this revision.Jun 28 2017, 12:03
Herald added a reviewer: Restricted Project. · View Herald TranscriptJun 28 2017, 12:03
deadalnix updated this revision to Diff 705.Jun 28 2017, 12:04

Remove dead assignement

freetrader requested changes to this revision.Jun 28 2017, 15:17

Minor things only.

Testing on my system shows the code is solid.
I executed the test plan and did 100+ iterations of abc-p2p-fullblocktest .

I'm going to withdraw D283 in favor of this change.

qa/rpc-tests/test_framework/mininode.py
1685 ↗(On Diff #705)

I think it would better to explicitly 'pass' BlockingIOError and to raise any other unexpected exceptions.

1724 ↗(On Diff #705)

Now that this method is changed to a proper function, it would be better to do return None instead of just return .

1729 ↗(On Diff #705)

dito

1734 ↗(On Diff #705)

dito

1739 ↗(On Diff #705)

dito

1744 ↗(On Diff #705)

dito

1753 ↗(On Diff #705)

dito

This revision now requires changes to proceed.Jun 28 2017, 15:17
deadalnix added inline comments.Jun 28 2017, 16:16
qa/rpc-tests/test_framework/mininode.py
1685 ↗(On Diff #705)

This has nothing to do with that fix.

deadalnix updated this revision to Diff 708.Jun 28 2017, 16:17
deadalnix edited edge metadata.

return None

freetrader accepted this revision.Jun 28 2017, 16:20
This revision is now accepted and ready to land.Jun 28 2017, 16:20
This revision was automatically updated to reflect the committed changes.