init: Keep track of whether data directory locked, don't cleanup if not #10818

pull laanwj wants to merge 1 commits into bitcoin:master from laanwj:2017_05_locked_datadir changing 1 files +14 −0
  1. laanwj commented at 6:58 PM on July 13, 2017: member

    Keep a flag in init.cpp indicating whether the data directory was locked.

    If not, Interrupt and Shutdown are no-ops. This avoids things from being cleaned up if they were created by another instance.

    I think this is the most robust, sure solution to #10815.

    n.b.: We can't simple do "don't call Interrupt/Shutdown if Init*() failed" because some of the things needs to be interrupted and shut down in case of an error later in initialization when some things have already been started.

  2. init: Keep track of whether data directory locked, don't cleanup if not
    Keep a flag indicating whether the data directory was locked.
    
    If not, Interrupt and Shutdown are no-ops. This avoids things from being
    cleaned up if they were created by another instance.
    73b6b4e7c0
  3. laanwj added the label Bug on Jul 13, 2017
  4. laanwj added this to the milestone 0.15.0 on Jul 13, 2017
  5. morcos commented at 9:33 PM on July 13, 2017: member

    This seems right to me and it solved the problem, but I'm not confident enough in understanding startup/shutdown to actually give it an ACK.

    Thanks!

  6. jonasschnelli commented at 8:13 AM on July 14, 2017: contributor

    utACK 73b6b4e7c0a450bb88074a7d59a9237b4703302b

  7. achow101 commented at 6:21 PM on July 14, 2017: member

    utACK 73b6b4e7c0a450bb88074a7d59a9237b4703302b

  8. TheBlueMatt commented at 10:34 PM on July 14, 2017: member

    Why not just make AppInitSanityCheck actually take the lock instead of just probing? It seems strange to call the entire shutdown sequence instead when literally none of it is needed when we already have a framework for skipping it (ala if AppinitSanityCheck fails, except for GUI, which really should be fixed in GUI, not by adding a boolean).

  9. sipa commented at 11:41 PM on July 14, 2017: member

    @TheBlueMatt I'm confused how that would help here.

  10. TheBlueMatt commented at 11:51 PM on July 14, 2017: member

    My point is that this is (effecitlvely) not a problem in bitcoind. The issue in bitcoin-qt is that it calls Shutdown() where it should not (and bitcoind does not). If we want to separately fix the race that is also present in bitcoind, we should stop doing this strange LockDataDirectory(true)...one function return/call later...LockDataDirectory(false) thing.

  11. in src/init.cpp:79 in 73b6b4e7c0
      74 | @@ -75,6 +75,9 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
      75 |  std::unique_ptr<CConnman> g_connman;
      76 |  std::unique_ptr<PeerLogicValidation> peerLogic;
      77 |  
      78 | +/** Set at startup if the data directory was succesfully locked */
      79 | +bool g_locked_data_directory = false;
    


    promag commented at 11:56 PM on July 14, 2017:

    Should be static and atomic?


    laanwj commented at 8:04 AM on July 15, 2017:

    static ok, atomic no, there's no concurrent modification as the flag is set from one place in the initialization sequence.

  12. laanwj commented at 8:09 AM on July 15, 2017: member

    when we already have a framework for skipping it (ala if AppinitSanityCheck fails, except for GUI, which really should be fixed in GUI, not by adding a boolean).

    The point, which I explain in #10815 (comment), is that that mechanism ALSO doesn't work for bitcoind.

    If we want to separately fix the race that is also present in bitcoind, we should stop doing this strange LockDataDirectory(true)...one function return/call later...LockDataDirectory(false) thing.

    The point of that 'strange sequence' is to be able to give a proper error in the case of -daemon. If you take the data directory lock before forking, bad things happen. If you only take it after the fork, it's impossible to print an error to the standard output as that has been detached. That's why the probing is done.

    Do you mean calling LockDataDirectory in a separate initialization step after daemonizing? That could work, though as it is already so easy to introduce bugs like this I thought it was more robust to add a flag.

  13. laanwj referenced this in commit ceec6cb45e on Jul 15, 2017
  14. laanwj commented at 8:49 AM on July 15, 2017: member

    Closign in favor of #10832

  15. laanwj closed this on Jul 15, 2017

  16. laanwj referenced this in commit dba485d651 on Jul 17, 2017
  17. laanwj referenced this in commit 89bb0365b9 on Jul 17, 2017
  18. fametrano referenced this in commit cbf5ba4603 on Aug 4, 2017
  19. JeremyRubin referenced this in commit 0bb52fb5e4 on Aug 9, 2017
  20. HashUnlimited referenced this in commit 9e6a1ead63 on Mar 9, 2018
  21. PastaPastaPasta referenced this in commit 6fb74ead60 on Aug 2, 2019
  22. PastaPastaPasta referenced this in commit 2d96901cc7 on Aug 6, 2019
  23. barrystyle referenced this in commit 29f1a577ea on Jan 22, 2020
  24. 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