Skip to content

fix(swarm): bound Connection::poll iterations for cooperative scheduling - #6513

Open
akshitj11 wants to merge 2 commits into
libp2p:masterfrom
akshitj11:fix/6438-connection-poll-budget
Open

fix(swarm): bound Connection::poll iterations for cooperative scheduling#6513
akshitj11 wants to merge 2 commits into
libp2p:masterfrom
akshitj11:fix/6438-connection-poll-budget

Conversation

@akshitj11

@akshitj11 akshitj11 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Bound the fixed-point loop in Connection::poll with a 128-iteration cooperative budget.
When exhausted, the connection returns Poll::Pending and self-wakes so the executor can
schedule other tasks. Deliverable Poll::Ready paths (handler events, address changes,
keep-alive errors) are unchanged.

Fixes #6438

AI Assistance Disclosure

Used AI tooling for implementation and review; all changes self-reviewed and tested locally.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

Cap the fixed-point loop in Connection::poll with a 128-iteration budget
and self-wake on exhaustion so Tokio workers are not monopolized during
large muxer/handler progress bursts.

Fixes libp2p#6438

@dariusc93 dariusc93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. Left a couple of comments. Also, can you revert the description to the PR template? :)

Comment thread Cargo.toml Outdated
Comment thread swarm/src/connection.rs Outdated
Comment thread swarm/src/connection.rs
Revert version to unpublished 0.48.0, replace budget macro with function.
@akshitj11

Copy link
Copy Markdown
Contributor Author

@dariusc93 made the changes that was asked , you can review it :)

@akshitj11
akshitj11 requested a review from dariusc93 August 1, 2026 06:24
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.

swarm: Connection::poll regularly exceeds Tokio's 50 µs slow-poll threshold

2 participants