CodeChain-io / codechain

CodeChain's official implementation in Rust.
https://codechain.io/
GNU Affero General Public License v3.0
258 stars 51 forks source link

Fix a deadlock in miner.rs #1968

Closed majecty closed 4 years ago

majecty commented 4 years ago

There is a deadlock between immune_users and mem_pool.

A client worker thread locks immune_users first and mem_pool second in prepare_block function.

An HTTP thread locks mem_pool first in import_own_transactions function and locks immune_users in add_transactions_to_pool function.

It seems that this deadlock is added when we add immune_users lock. We need to review the lock of immune_users.

HoOngEe commented 4 years ago

How about just moving the line let immune_users = self.immune_users.read(); to the 565th line ?

majecty commented 4 years ago

@HoOngEe @sgkim126 I agree with Seulgi. Locking mem_pool first will be better.