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
Branch
fixtstracecond
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 433
Build 433: arc lint + arc unit

Event Timeline

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

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

1724

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

1729

dito

1734

dito

1739

dito

1744

dito

1753

dito

This revision now requires changes to proceed.Jun 28 2017, 15:17
qa/rpc-tests/test_framework/mininode.py
1685

This has nothing to do with that fix.

deadalnix edited edge metadata.

return None

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