Content-Length: 223597 | pFad | http://github.com/tokio-rs/tokio/issues/7108

74 MPSC queue hangs on repeated polling · Issue #7108 · tokio-rs/tokio · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPSC queue hangs on repeated polling #7108

Open
jshaw-jump opened this issue Jan 17, 2025 · 1 comment
Open

MPSC queue hangs on repeated polling #7108

jshaw-jump opened this issue Jan 17, 2025 · 1 comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-coop Module: tokio/coop M-sync Module: tokio/sync

Comments

@jshaw-jump
Copy link

jshaw-jump commented Jan 17, 2025

Version

└── tokio v1.43.0
    └── tokio-macros v2.5.0 (proc-macro)

Platform
RHEL 8
x86_64
Intel CascadeLake

Description
The MPSC channel receiver is failing to receive messages when being repeatedly polled. I notice that it will receive exactly 128 elements (4 underlying blocks) before failing.

Here is a reproduction. Note that the select! macro simplifies the code here, but the issue also reproduces if the select! is replaced by a custom future that repeatedly invokes Future::poll on the Receiver object, verifying that the select! isn't a factor.

use tokio::{select, sync::mpsc};

#[tokio::main]
async fn main() {
    let (sender, mut receiver) = mpsc::channel(2);

    tokio::spawn(async move {
        for n in 0usize.. {
            sender.send(n).await.unwrap();
        }
    });

    loop {
        select! {
            msg = receiver.recv() => println!("Received {}", msg.unwrap()),
            () = std::future::ready(()) => {}
        }
    }
}

The output is as follows. No logging is observed after 128 elements have been received.

Received 0
Received 1
Received 2
... (lines omitted for brevity) ...
Received 127
@jshaw-jump jshaw-jump added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Jan 17, 2025
@Darksonn Darksonn added M-sync Module: tokio/sync M-coop Module: tokio/coop labels Jan 18, 2025
@Darksonn
Copy link
Contributor

This is due to Tokio's coop feature where Tokio attempts to force tasks to yield. The channel will return Pending until the task yields to the runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-coop Module: tokio/coop M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/tokio-rs/tokio/issues/7108

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy