Skip to content

Fix thread starvation in test_single_channel_multiple_mpp#4396

Open
jkczyz wants to merge 1 commit intolightningdevkit:mainfrom
jkczyz:2026-02-fix-hanging-test
Open

Fix thread starvation in test_single_channel_multiple_mpp#4396
jkczyz wants to merge 1 commit intolightningdevkit:mainfrom
jkczyz:2026-02-fix-hanging-test

Conversation

@jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Feb 6, 2026

The busy-wait loop polling for PaymentClaimed events had no yield, causing it to continuously acquire ChannelManager locks via get_and_clear_pending_events(). This could starve the claim_funds thread of lock access, preventing it from ever queuing the event. Add a yield_now() call matching the pattern used by the other two spin loops in this test.

The busy-wait loop polling for PaymentClaimed events had no yield,
causing it to continuously acquire ChannelManager locks via
get_and_clear_pending_events(). This could starve the claim_funds
thread of lock access, preventing it from ever queuing the event.
Add a yield_now() call matching the pattern used by the other two
spin loops in this test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Feb 6, 2026

👋 Thanks for assigning @TheBlueMatt as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@jkczyz
Copy link
Contributor Author

jkczyz commented Feb 6, 2026

I asked Claude to fix this hanging test. This is what it came up with for a plan:

 ▐▛███▜▌   Claude Code v2.1.32
▝▜█████▛▘  Opus 4.6 · API Usage Billing
  ▘▘ ▝▝    ~/src/rust-lightning-legacy-tlv-read

╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Plan to implement                                                                                    │
│                                                                                                      │
│ Plan: Fix test_single_channel_multiple_mpp hang                                                      │
│                                                                                                      │
│ Problem                                                                                              │
│                                                                                                      │
│ The thrd_event busy-wait loop at lines 4708-4718 spins with no yield, continuously                   │
│ acquiring ChannelManager locks via get_and_clear_pending_events(). Under heavy load                  │
│ this can starve the claim_funds thread of lock access, preventing it from ever queuing               │
│ the PaymentClaimed event the loop is waiting for.                                                    │
│                                                                                                      │
│ The other two spin loops in this test (lines 4730-4731 and 4770-4771) already call                   │
│ std::thread::yield_now(), but the event loop does not.                                               │
│                                                                                                      │
│ File: lightning/src/ln/chanmon_update_fail_tests.rs                                                  │
│                                                                                                      │
│ Change: Add yield_now() to event polling loop (~line 4708)                                           │
│                                                                                                      │
│ Current:                                                                                             │
│ let thrd_event = std::thread::spawn(move || {                                                        │
│     let mut have_event = false;                                                                      │
│     while !have_event {                                                                              │
│         let mut events = event_node.get_and_clear_pending_events();                                  │
│         // ...                                                                                       │
│     }                                                                                                │
│ });                                                                                                  │
│                                                                                                      │
│ New:                                                                                                 │
│ let thrd_event = std::thread::spawn(move || {                                                        │
│     let mut have_event = false;                                                                      │
│     while !have_event {                                                                              │
│         let mut events = event_node.get_and_clear_pending_events();                                  │
│         // ...                                                                                       │
│         if !have_event {                                                                             │
│             std::thread::yield_now();                                                                │
│         }                                                                                            │
│     }                                                                                                │
│ });                                                                                                  │
│                                                                                                      │
│ This gives the claim_funds thread a chance to acquire the contested locks between                    │
│ iterations, matching the yield pattern used elsewhere in the test.                                   │
│                                                                                                      │
│ Verification                                                                                         │
│                                                                                                      │
│ 1. cargo +1.75.0 fmt --all                                                                           │
│ 2. cargo +1.75.0 test -p lightning -- test_single_channel_multiple_mpp                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

@jkczyz jkczyz requested a review from TheBlueMatt February 6, 2026 23:43
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.

2 participants