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.