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

Flushing stdout with a binary protocol does not work #1527

Closed
jothan opened this issue Sep 1, 2019 · 2 comments
Closed

Flushing stdout with a binary protocol does not work #1527

jothan opened this issue Sep 1, 2019 · 2 comments

Comments

@jothan
Copy link
Contributor

jothan commented Sep 1, 2019

I'm having trouble with a binary protocol that does not use newlines as line separators. stdout seems to flush immediately only when there is a newline in the output.

I have included a snippet to reproduce this issue.

Flushing the underlying std stream works, but only when the async stream was flushed first.

stderr has the expected behaviour of flushing immediately correctly.

Version

0.2.0-alpha.4

Platform

Linux 4.19.0-5-amd64 #1 SMP Debian 4.19.37-5+deb10u2 (2019-08-08) x86_64 GNU/Linux

Subcrates

Description

use std::io::Write;
use std::time::Duration;

use tokio::prelude::*;
use tokio::timer::delay;
use tokio::io::{stdout};

async fn works() -> Result<(), Box<dyn std::error::Error>> {
    let mut output = stdout();
    output.write_all(b"hello").await?;
    output.flush().await?;
    std::io::stdout().flush()?;

    Ok(())
}

async fn should_work() -> Result<(), Box<dyn std::error::Error>> {
    let mut output = stdout();
    output.write_all(b"hello").await?;
    output.flush().await?;

    Ok(())
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Both calls should output "hello" without a newline immediately
    //works().await?;
    should_work().await?;

    let when = tokio::clock::now() + Duration::from_secs(5);
    delay(when).await;
    
    Ok(())
}
@jothan
Copy link
Contributor Author

jothan commented Sep 1, 2019

Adding inner.flush() in Blocking::poll_flush() seems to fix the behaviour. I am not sure where to call the lower layer flush.

@carllerche
Copy link
Member

Fixed by #1528

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

No branches or pull requests

2 participants