Files
bitcoin/src
Vasil Dimov f46b678acf qt: lock cs_main, m_cached_tip_mutex in that order
Always lock the mutexes `cs_main` and `m_cached_tip_mutex` in
the same order: `cs_main`, `m_cached_tip_mutex`. Otherwise we may end up
in a deadlock.

`ClientModel::m_cached_tip_blocks` is protected by
`ClientModel::m_cached_tip_mutex`. There are two access paths that
lock the two mutexes in opposite order:

```
validation.cpp:2868 CChainState::ActivateBestChain(): lock cs_main
validation.cpp:2916 CChainState::ActivateBestChain(): call uiInterface.NotifyBlockTip()
ui_interface.cpp:52 CClientUIInterface::NotifyBlockTip(): go deep in boost
...
qt/clientmodel.cpp:255 BlockTipChanged(): lock m_cached_tip_mutex
```

and

```
qt/clientmodel.cpp:119 ClientModel::getBestBlockHash(): lock m_cached_tip_mutex
qt/clientmodel.cpp:121 ClientModel::getBestBlockHash(): call m_node.getBestBlockHash()
interfaces/node.cpp:200 NodeImpl::getBestBlockHash(): lock cs_main
```

From `debug.log`:

```
POTENTIAL DEADLOCK DETECTED
Previous lock order was:
 m_cs_chainstate validation.cpp:2851
 (1) cs_main validation.cpp:2868
 ::mempool.cs validation.cpp:2868
 (2) clientmodel->m_cached_tip_mutex qt/clientmodel.cpp:255
Current lock order is:
 (2) m_cached_tip_mutex qt/clientmodel.cpp:119
 (1) ::cs_main interfaces/node.cpp:200
```

The possible deadlock was introduced in
https://github.com/bitcoin/bitcoin/pull/17993
2020-06-01 17:14:43 +02:00
..
2020-02-09 07:44:29 -08:00
2020-04-16 13:33:09 -04:00
2018-12-29 10:15:01 +01:00
2020-04-16 13:33:09 -04:00
2019-02-22 17:38:45 -08:00
2018-07-27 07:15:02 -04:00
2018-07-27 07:15:02 -04:00
2020-04-16 13:33:09 -04:00
2018-07-27 07:15:02 -04:00
2018-07-27 07:15:02 -04:00
2020-04-16 13:33:09 -04:00
2020-04-30 09:19:14 -04:00
2020-04-30 11:16:56 +02:00
2018-07-27 07:15:02 -04:00
2020-05-25 11:27:07 -07:00
2020-04-16 13:33:09 -04:00
2018-07-27 07:15:02 -04:00