Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(qt): Fix overlapping directory lock attempts when restarting Dash Qt #6540

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

kwvg
Copy link
Collaborator

@kwvg kwvg commented Jan 27, 2025

Expected Behavior

  • Start Dash Qt
  • Go to Window > Wallet Repair and click on "Rebuild Index"
  • Dash Qt restarts and starts reindexing chain
  • 🎉

Actual Behavior

  • Start Dash Qt
  • Go to Window > Wallet Repair and click on "Rebuild Index"
  • Dash Qt exits and on the restart, get greeted by "Error: Cannot obtain a lock on data directory /home/dash/.dashcore. Dash Core is probably already running."
  • Run the client again
  • Reindexing starts

Additional Information

  • Running the client after reindexing is requested (i.e. on restart) was found to result in a nullptr-induced crash (see below) even though DeploymentActiveAfter() handles a nullptr case (source). This has been resolved by returning early if pindex is a nullptr. Addressed by dash#6537, fix dropped from this PR.

    Crash trace:
    Posix Signal: Segmentation fault
      0#: (0x557D376F7454) stacktraces.cpp          - HandlePosixSignal(int)
      1#: (0x7F1F6B65B050) <unknown-file>           - ???
      2#: (0x557D36FA2C4F) deploymentstatus.h:20    - DeploymentActiveAfter(CBlockIndex const*, Consensus::Params const&, Consensus::BuriedDeployment)
      3#: (0x557D36FA2C4F) deterministicmns.cpp:220 - CDeterministicMNList::GetProjectedMNPayees(gsl::not_null<CBlockIndex const* const>, int) const
      4#: (0x557D36F2A271) stl_iterator.h:1028      - __gnu_cxx::__normal_iterator<std::shared_ptr<CDeterministicMN const> const*, std::vector<std::shared_ptr<CDeterministicMN const>, std::allocator<std::shared_ptr<CDeterministicMN const> > > >::__normal_iterator(std::shared_ptr<CDeterministicMN const> const* const&)
      5#: (0x557D36F2A271) stl_vector.h:821         - std::vector<std::shared_ptr<CDeterministicMN const>, std::allocator<std::shared_ptr<CDeterministicMN const> > >::begin() const
      6#: (0x557D36F2A271) stl_vector.h:1008        - std::vector<std::shared_ptr<CDeterministicMN const>, std::allocator<std::shared_ptr<CDeterministicMN const> > >::empty() const
      7#: (0x557D36F2A271) masternodelist.cpp:169   - MasternodeList::updateDIP3List()
      8#: (0x557D36F29D30) masternodelist.cpp:147   - MasternodeList::updateDIP3ListScheduled()
      9#: (0x557D37FEE969) <unknown-file>           - ???
     10#: (0x557D37FF4AA2) <unknown-file>           - ???
     11#: (0x557D37FE7843) <unknown-file>           - ???
     12#: (0x557D3821AC0C) <unknown-file>           - ???
     13#: (0x557D3821BEDE) <unknown-file>           - ???
     14#: (0x557D37FCA888) <unknown-file>           - ???
     15#: (0x557D3800C223) <unknown-file>           - ???
     16#: (0x557D3800A02D) <unknown-file>           - ???
     17#: (0x557D3813FD4E) <unknown-file>           - ???
     18#: (0x557D36F57849) sendcoinsdialog.cpp:607  - SendCoinsDialog::addEntry()
    

Breaking Changes

None expected

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests (note: N/A)
  • I have made corresponding changes to the documentation (note: N/A)
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@kwvg kwvg added this to the 22.1 milestone Jan 27, 2025
@kwvg kwvg marked this pull request as ready for review January 27, 2025 05:48
Copy link

coderabbitai bot commented Jan 27, 2025

Walkthrough

The pull request introduces a new conditional block at the end of the PrepareShutdown function in src/init.cpp. This block checks if a restart is requested by calling RestartRequested(). If true, it invokes the ReleaseDirectoryLocks() function. This addition ensures that directory locks are explicitly released during the shutdown process when a restart is anticipated, rather than relying on the global context to handle this automatically. The overall structure and logic of the shutdown process remain unchanged, with no lines removed or modified. No changes were made to the declarations of exported or public entities in this diff.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43be934 and 59f9c51.

📒 Files selected for processing (1)
  • src/init.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/init.cpp
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Dependencies (linux64, x86_64-pc-linux-gnu)
  • GitHub Check: Build Dependencies (arm-linux, arm-linux-gnueabihf)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -359,6 +359,10 @@ void PrepareShutdown(NodeContext& node)

UnregisterAllValidationInterfaces();
GetMainSignals().UnregisterBackgroundSignalScheduler();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Release all directory locks. This is used for unit testing only, at runtime
 * the global destructor will take care of the locks.
 */

bitcoin says this one. Why should we do it manually?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we implement functionality (restarting, source) that Bitcoin doesn't. The problem occurs because of the following order:

  • Client started, global context initialized
  • Managed context initializes
    • Directory is locked
  • Client fully loaded, user requests a reindex
  • Managed context is destroyed
  • New client instance is started with amended runtime arguments for reindex
  • Old client instance finishes, global context is destroyed
    • Directory is unlocked

The problem is that we start the new client (source) before the client gets to fully shutter down (source), which means the directory is still locked when the new instance is trying to run, which results in deviation from expected behavior. This is resolved by releasing the directory locks explicitly, to allow for the new instance to take over.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably wrap it in if (RestartRequested()) { ... } to avoid executing it on shutdown

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapped in RestartRequested() and updated comment in latest push

@kwvg kwvg requested a review from knst January 27, 2025 09:32
Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 59f9c51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants