Skip to content

Conversation

ViktorT-11
Copy link
Collaborator

Fixes #9109

Before this PR, lnd could become unresponsive to shutdown signals during the IsSynced check, which can sometimes take a long time to complete. This caused delays in shutting down lnd.

I'm pushing this as a draft PR for now, as there are several possible solutions to consider:

  1. Cancelable context: The cleanest approach might be to pass a cancelable context into the IsSynced function, allowing it to exit immediately when a shutdown signal is received. However, this would require updates to both the btcwallet and btcd repositories, and we would need to wait for new releases with these changes. There are also two activeChainControl.ChainIO.GetBestBlock() calls in lnd.go—just before and after this PR’s changes—which could block as well, though we haven't seen extended delays in those calls.

  2. Listening to async channels: Another option is to modify the IsSynced function to listen to the underlying async channels from GetBestBlock and GetBlockHeader. This would also require changes to the btcwallet repo and a release.

To reviewers: I would appreciate feedback on which approach you think is best. :)

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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 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.

Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Approach ack.

lnd.go Outdated
Err error
}

syncCheckLoop:
Copy link
Member

Choose a reason for hiding this comment

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

nit: would personally prefer not using syncCheckLoop and just do break

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! The reason for the labelled loop is that just using a break would've just cancelled the select statement and not the outer loop.

I refactored this a bit though so that just canceling the select statement works fine :)! I also prefer the new version without the syncCheckLoop label, as it makes it a bit clearer what the actual loop is for.

lnd.go Outdated
// If we're not yet synced, we'll wait for a second before
// checking again.
select {
case <-interceptor.ShutdownChannel():
Copy link
Member

Choose a reason for hiding this comment

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

looks like we don't need to catch it again here since after 1s it will go to the next iteration.

Copy link
Collaborator Author

@ViktorT-11 ViktorT-11 Sep 30, 2024

Choose a reason for hiding this comment

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

I still included this change, as we'll else block the shutdown for 1 second while waiting for this. If you think that's an unnecessary optimisation, I'm ok with removing it though and just keep the:
<-time.After(time.Second)

@ViktorT-11 ViktorT-11 force-pushed the 2024-09-sync-lock-fix branch from bc66e8d to cb39820 Compare September 30, 2024 11:36
@ViktorT-11
Copy link
Collaborator Author

Thanks a lot for the review @yyforyongyu 🙏! Given the Approach ack, I'll take this out of draft mode :)

@ViktorT-11 ViktorT-11 marked this pull request as ready for review September 30, 2024 11:44
Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

tACK 🔥

A few style suggestions but otherwise lgtm!

Prior to this commit, lnd could become unresponsive to shutdown signals
during the `IsSynced` check. Since the `IsSynced` check can occasionally
take a long time to complete, this could result in lnd failing to shut
down promptly.
@ViktorT-11 ViktorT-11 force-pushed the 2024-09-sync-lock-fix branch from cb39820 to 52b3a06 Compare October 1, 2024 09:43
@ViktorT-11
Copy link
Collaborator Author

Thanks a lot for the review @ellemouton 🙏! I've addressed your feedback :)

@lightninglabs-deploy
Copy link

@yyforyongyu: review reminder
@ViktorTigerstrom, remember to re-request review from reviewers when ready

Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

LGTM❤️

@guggero guggero merged commit 6992ecc into lightningnetwork:master Oct 17, 2024
26 of 32 checks passed
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.

6 participants