cs_main lock not held when reindexing blocks on disk? #5330

issue laanwj opened this issue on November 20, 2014
  1. laanwj commented at 4:07 PM on November 20, 2014: member

    I've added an assertlockheld(cs_main) in coins.cpp, and I get the following stack trace when trying to reindex:

    Assertion failed: lock cs_main not held in coins.cpp:194; locks held:
    
    [#3](/bitcoin-bitcoin/3/)  0x54beb616 in AssertLockHeldInternal (pszName=0x0, pszFile=0x1 <error: Cannot access memory at address 0x1>, nLine=nLine@entry=194, cs=0x54e08b48 <cs_main>) at sync.cpp:149
    [#4](/bitcoin-bitcoin/4/)  0x54bb52ec in CCoinsViewCache::Flush (this=0x54e7b9f8) at coins.cpp:194
    [#5](/bitcoin-bitcoin/5/)  0x54afee4c in FlushStateToDisk (state=..., mode=mode@entry=FLUSH_STATE_PERIODIC) at main.cpp:1805
    [#6](/bitcoin-bitcoin/6/)  0x54b069d2 in ActivateBestChain (state=..., pblock=pblock@entry=0x2f9fed08) at main.cpp:2127
    [#7](/bitcoin-bitcoin/7/)  0x54b06ef2 in ProcessNewBlock (state=..., pfrom=pfrom@entry=0x0, pblock=pblock@entry=0x2f9fed08, dbp=dbp@entry=0x2f9feddc) at main.cpp:2579
    [#8](/bitcoin-bitcoin/8/)  0x54b0739e in LoadExternalBlockFile (fileIn=fileIn@entry=0x2fa007a8, dbp=dbp@entry=0x2f9feddc) at main.cpp:3191
    [#9](/bitcoin-bitcoin/9/)  0x54ad574c in ThreadImport (vImportFiles=std::vector of length 0, capacity 0) at init.cpp:417
    
  2. laanwj added the label Bug on Nov 20, 2014
  3. laanwj added the label Priority Medium on Nov 20, 2014
  4. laanwj commented at 4:08 PM on November 20, 2014: member

    Probably need a LOCK(cs_main) before the call to ProcessNewBlock in LoadExternalBlockFile.

  5. sipa commented at 4:14 PM on November 20, 2014: member

    Is this on #5241?

    No, ProcessNewBlock should run without cs_main, otherwise the entire reorg that may result would be done without releasing the lock.

  6. sipa commented at 4:17 PM on November 20, 2014: member

    I've added a LOCK(cs_main) to the FlushStateToDisk function in #5241.

  7. laanwj commented at 4:17 PM on November 20, 2014: member

    Is this on #5241?

    Yes.

    No, ProcessNewBlock should run without cs_main, otherwise the entire reorg that may result would be done without releasing the lock.

    OK. But somewhere along the call chain it should acquire the lock.

    Edit: OK will re-cherry-pick.

  8. laanwj closed this on Nov 20, 2014

  9. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me