Skip to content

Fix thread starvation in test_single_channel_multiple_mpp#4396

Merged
TheBlueMatt merged 1 commit intolightningdevkit:mainfrom
jkczyz:2026-02-fix-hanging-test
Feb 7, 2026
Merged

Fix thread starvation in test_single_channel_multiple_mpp#4396
TheBlueMatt merged 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
@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.03%. Comparing base (817ab5e) to head (1829dc9).
⚠️ Report is 34 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4396      +/-   ##
==========================================
+ Coverage   86.01%   86.03%   +0.01%     
==========================================
  Files         156      156              
  Lines      102857   103091     +234     
  Branches   102857   103091     +234     
==========================================
+ Hits        88476    88691     +215     
- Misses      11871    11889      +18     
- Partials     2510     2511       +1     
Flag Coverage Δ
tests 86.03% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

shitty mutex impl for this to hang, but it won't hurt so why not.

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@TheBlueMatt TheBlueMatt merged commit 92a8c88 into lightningdevkit:main Feb 7, 2026
19 of 21 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.

3 participants