Skip to content

Commit

Permalink
Merge #1921: [Core] Lock cs_vSend and cs_inventory in a consistent or…
Browse files Browse the repository at this point in the history
…der even in TRY

0475239 Lock cs_vSend and cs_inventory in a consistent order even in TRY (random-zebra)

Pull request description:

  Fixes another inconsistency found with #1920 :
  ```
  2020-10-15 23:43:11 POTENTIAL DEADLOCK DETECTED
  2020-10-15 23:43:11 Previous lock order was:
  2020-10-15 23:43:11  (1) pnode->cs_vSend net.cpp:1152 (TRY) (in thread pivx-net)
  2020-10-15 23:43:11  (2) pnode->cs_inventory net.cpp:1154 (TRY) (in thread pivx-net)
  2020-10-15 23:43:11 Current lock order is:
  2020-10-15 23:43:11  pnode->cs_sendProcessing net.cpp:1898 (in thread pivx-msghand)
  2020-10-15 23:43:11  cs_main net_processing.cpp:1992 (TRY) (in thread pivx-msghand)
  2020-10-15 23:43:11  (2) pto->cs_inventory net_processing.cpp:2081 (in thread pivx-msghand)
  2020-10-15 23:43:11  (1) pnode->cs_vSend net.cpp:2568 (in thread pivx-msghand)
  ```

  backporting the only missing commit from upstream bitcoin#9674

ACKs for top commit:
  furszy:
    utACK 0475239
  Fuzzbawls:
    utACK 0475239

Tree-SHA512: e7183d09f5e00dbccd5d1d3ec46d81b7eeea692350e33809477811b681a1ce7278b92cf7ef1d2d33c13aaa5572b98bb152931a041492db05d3d499818fc1d1df
  • Loading branch information
furszy committed Oct 17, 2020
2 parents ba9c3ee + 0475239 commit 14f0e97
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,12 @@ void CConnman::ThreadSocketHandler()
if (pnode->GetRefCount() <= 0) {
bool fDelete = false;
{
TRY_LOCK(pnode->cs_vSend, lockSend);
if (lockSend) {
TRY_LOCK(pnode->cs_inventory, lockInv);
if (lockInv)
fDelete = true;
TRY_LOCK(pnode->cs_inventory, lockInv);
if (lockInv) {
TRY_LOCK(pnode->cs_vSend, lockSend);
if (lockSend) {
fDelete = true;
}
}
}
if (fDelete) {
Expand Down

0 comments on commit 14f0e97

Please sign in to comment.