openethereum / parity-ethereum

The fast, light, and robust client for Ethereum-like networks.
Other
6.82k stars 1.69k forks source link

ethcore/test_helpers: fix deadlock caused by double read lock #11767

Open BurtonQin opened 4 years ago

BurtonQin commented 4 years ago

Similar to #11766,

  1. In block_hash(), the two numbers.read() may be interleaved by numbers.write() from another thread. https://github.com/openethereum/openethereum/blob/f8cbdadfaaef30febbeab1ec5b7331a74ec7856a/ethcore/src/test_helpers/test_client.rs#L360 The fix is to use one numbers.read() instead of two.
  2. In chain_info(), the two difficulty.read()(first_block.read(), ancient_block.read()) may be interleaved by their corresponding write lock from another thread. https://github.com/openethereum/openethereum/blob/f8cbdadfaaef30febbeab1ec5b7331a74ec7856a/ethcore/src/test_helpers/test_client.rs#L491-L502 I lift the read locks and order them as they are declared. Currently, no conflicting lock order is found.