Skip to content

Release completed cancellable tasks#997

Open
tnull wants to merge 4 commits into
lightningdevkit:mainfrom
tnull:2026-07-cancel-task-leaks
Open

Release completed cancellable tasks#997
tnull wants to merge 4 commits into
lightningdevkit:mainfrom
tnull:2026-07-cancel-task-leaks

Conversation

@tnull

@tnull tnull commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Avoid retaining completed Tokio task allocations for the node lifetime while preserving shutdown cancellation and restart semantics. This fixes a considerable memory leak as previously we'd retain the JoinSeted task's allocations until stop/join_next, as tokio thankfully only notes in the https://docs.rs/tokio-util/latest/tokio_util/task/task_tracker/struct.TaskTracker.html#comparison-to-joinset.

Thanks to @elnosh for reporting this leak.

@ldk-reviews-bot

ldk-reviews-bot commented Jul 20, 2026

Copy link
Copy Markdown

I've assigned @tankyleo 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.

tnull added 4 commits July 21, 2026 10:14
Avoid retaining completed Tokio task allocations for the node
lifetime while preserving shutdown cancellation and restart semantics.

Co-Authored-By: HAL 9000
Remove pending LSPS request state when callers time out or are
cancelled so unresponsive services cannot grow request maps.

Co-Authored-By: HAL 9000
Clear per-peer connection state when the leading task is cancelled
so later callers can retry and existing subscribers do not hang.

Co-Authored-By: HAL 9000
Restore wallet sync status and notify waiting callers when the task
performing a sync is cancelled, allowing later sync attempts to run.

Co-Authored-By: HAL 9000
@tnull
tnull force-pushed the 2026-07-cancel-task-leaks branch from 3553a89 to fb5fbc8 Compare July 21, 2026 09:05
@tnull

tnull commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased after #956 landed.

@elnosh elnosh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK fix in 08d3b5d

I'm less familiar with the code in some of the other commits, specially in liquidity. Some of the changes implementing the different Guards took me quite a bit to understand so I would've appreciated some comments but they look correct. Specifically:

  • reason for PendingRequestGuard needing the tokens for the pending requests in liquidity/mod.rs
  • PendingRequest in liquidity separating the owner Sender from the other followers Vec<oneshot::Sender<T>>. In connection.rs there's just one vec for all the senders.

These make sense now but not particularly obvious so adding comments is just a suggestion, I'm fine with it as-is

Comment thread src/connection.rs
Comment on lines 301 to 305
debug_assert!(
false,
"Failed to send connection result to subscribers: {:?}",
e
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

similar to fb5fbc8 this debug_assert could be removed as receiver from this pending connection attempt might have been dropped.

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