Skip to content

Conversation

yyforyongyu
Copy link
Member

@yyforyongyu yyforyongyu commented Jul 7, 2025

Make sure we don't prematurely close the quit chans. Fixes the panic,

panic: close of closed channel

goroutine 2397 [running]:
github.com/lightningnetwork/lnd/contractcourt.(*UtxoNursery).Stop(0x400224e340)
    github.com/lightningnetwork/lnd@v0.19.1-beta/contractcourt/utxonursery.go:332 +0x10c
github.com/lightningnetwork/lnd.cleaner.run({0x4001d9eb80, 0x0?, 0x4000bb17a8?})
    github.com/lightningnetwork/lnd@v0.19.1-beta/server.go:2187 +0x44
github.com/lightningnetwork/lnd.(*server).Start(0x40012ea708, {0x43764b8, 0x40006fad80})
    github.com/lightningnetwork/lnd@v0.19.1-beta/server.go:2654 +0xac
github.com/lightningnetwork/lnd.Main.func12()
    github.com/lightningnetwork/lnd@v0.19.1-beta/lnd.go:761 +0x30
created by github.com/lightningnetwork/lnd.Main in goroutine 356
    github.com/lightningnetwork/lnd@v0.19.1-beta/lnd.go:760 +0x2df4

This will keep node in panic as the quit chan was closed in Start, and we always call Stop to close the quit, which will cause a panic. This is also because we have changed to cleanup order in 653e2f3.

@yyforyongyu yyforyongyu added this to the v0.19.2 milestone Jul 7, 2025
@yyforyongyu yyforyongyu self-assigned this Jul 7, 2025
@yyforyongyu yyforyongyu added bug fix size/micro small bug fix or feature, less than 15 mins of review, less than 250 labels Jul 7, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @yyforyongyu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical panic within the contractcourt package's UtxoNursery component. The fix ensures that the component's quit channel is managed correctly, preventing it from being closed multiple times during startup failures, which previously led to a node-crashing 'close of closed channel' panic. The changes streamline channel lifecycle management by centralizing the quit channel closure to the Stop method.

Highlights

  • Bug Fix: Panic Prevention: Addressed a critical 'close of closed channel' panic that occurred when the UtxoNursery component failed to start up. Previously, the quit channel was prematurely closed in Start()'s error paths, leading to a panic when Stop() later attempted to close it again.
  • Channel Lifecycle Management: Refactored the UtxoNursery.Start() method to remove all instances of u.quit channel closure. This ensures that the quit channel is now exclusively closed within the Stop() method, adhering to proper component lifecycle management and preventing double-closure issues.
  • Improved Error Logging: Replaced the premature close(u.quit) calls with explicit error logging using utxnLog.Errorf before returning an error, providing better diagnostic information during startup failures.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a potential panic caused by closing the quit channel in multiple places. Centralizing the channel closure within the Stop method eliminates the risk of a double-close.

Comment on lines 291 to 292
// point forward, we must close the nursery's quit channel if we detect
// any failures during startup to ensure they terminate.

Choose a reason for hiding this comment

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

medium

The comment above this block is now outdated. It states that the quit channel should be closed if any failures are detected during startup, but the subsequent code no longer does this. Consider updating or removing the comment to avoid confusion.

Make sure we don't prematurely close the `quit` chans.
Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

LGTM, probably something for 19.2 ?

Copy link
Collaborator

@guggero guggero 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 b815109 into lightningnetwork:master Jul 7, 2025
37 of 40 checks passed
@yyforyongyu yyforyongyu deleted the fix-panic branch July 8, 2025 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix size/micro small bug fix or feature, less than 15 mins of review, less than 250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants