Skip to content

fix: yield to runtime on every 128 ChainStream polls#7254

Merged
hanabi1224 merged 1 commit into
mainfrom
hm/chain-stream-yield-every-100-polls
Jun 29, 2026
Merged

fix: yield to runtime on every 128 ChainStream polls#7254
hanabi1224 merged 1 commit into
mainfrom
hm/chain-stream-yield-every-100-polls

Conversation

@hanabi1224

@hanabi1224 hanabi1224 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Alternative fix to #7253
Tested with #7252

Bug: when the chain stream is consumed in a tight loop with no yield point inside, the task cannot be cancelled or rescheduled by tokio.

while stream.try_next().await?.is_some() {}

let mut stream = stream_chain(...);
while stream.try_next().await?.is_some() {}
stream.into_seen()

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes
    • Improved responsiveness of long-running chain stream processing by periodically yielding control back to the runtime. This helps cancellation take effect sooner and improves overall scheduling progress during extended operations.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

ChainStream gains an n_polled: usize counter initialized to 0. poll_next now increments the counter on each call and, every 128 polls, wakes the task and returns Poll::Pending.

Changes

ChainStream periodic yielding

Layer / File(s) Summary
n_polled counter and yield logic
src/ipld/util.rs
Adds n_polled: usize to ChainStream, initializes it in stream_chain, and updates poll_next to wake and return Poll::Pending on every 128th poll.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: ChainStream now yields back to the runtime periodically during polling.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/chain-stream-yield-every-100-polls
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/chain-stream-yield-every-100-polls

Comment @coderabbitai help to get the list of available commands.

@hanabi1224 hanabi1224 marked this pull request as ready for review June 29, 2026 14:50
@hanabi1224 hanabi1224 requested a review from a team as a code owner June 29, 2026 14:50
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and akaladarshi and removed request for a team June 29, 2026 14:50
@hanabi1224 hanabi1224 force-pushed the hm/chain-stream-yield-every-100-polls branch from efd0c96 to 29bbd0c Compare June 29, 2026 14:55
@hanabi1224 hanabi1224 changed the title fix: yield to runtime on every 100 ChainStream polls fix: yield to runtime on every 128 ChainStream polls Jun 29, 2026
@hanabi1224 hanabi1224 added the Snapshot Run snapshot tests label Jun 29, 2026
@hanabi1224 hanabi1224 added this pull request to the merge queue Jun 29, 2026
Merged via the queue into main with commit 9e0d4e2 Jun 29, 2026
34 of 56 checks passed
@hanabi1224 hanabi1224 deleted the hm/chain-stream-yield-every-100-polls branch June 29, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Snapshot Run snapshot tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants