You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Linux xpanse 4.19.4-arch1-1-ARCH #1 SMP PREEMPT Fri Nov 23 09:06:58 UTC 2018 x86_64 GNU/Linux
Description
I have a tokio::net::TcpStream that was just yielded by .incoming(), and need to synchronously read a single byte from it immediately after the connection comes in. I currently do that (stupidly) using the code below. It works fine with tokio 0.1.11 (playground), but on tokio 0.1.13, it hangs forever as the read_exact in the client never yields any bytes:
externcrate futures;externcrate tokio;use futures::Stream;use std::io::{prelude::*,ErrorKind};use std::{net, thread};fnmain(){let l = tokio::net::tcp::TcpListener::bind(&"127.0.0.1:0".parse().unwrap()).unwrap();let addr = l.local_addr().unwrap();let c = thread::spawn(move || {letmut c = net::TcpStream::connect(addr).unwrap();
c.write_all(&[42]).unwrap();
c.flush().unwrap();letmut buf = Vec::new();
c.read_to_end(&mut buf).unwrap();
buf
});
thread::spawn(move || {letmut rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on_all(l.incoming().for_each(|mut stream| {letmut tag = [0];letmut i = 0;whileletErr(e) = stream.read_exact(&mut tag[..]){
i += 1;if e.kind() == ErrorKind::WouldBlock{if i % 1_000_000 == 0{// ~= every 1seprintln!("still haven't gotten tag for new connection ({})", tag[0]);}
thread::yield_now();continue;}// well.. that failed quickly..eprintln!("gave up");returnErr(e);}eprintln!("all good");Ok(())}))});eprintln!("waiting for client...");
c.join().unwrap();eprintln!("client done!");}
strace shows that the read_exact after the accept never does any syscalls:
From discussion on Gitter, this was never intended to work. We're blocking the executor, which is a big no-no. In particular, we're blocking the executor from realizing that it needs to do a syscall (when it polls the reactor), and so therefore it doesn't do the syscall. This could be worked around either by using blocking (which would move the net reactor to a different thread), by using accept_std, reading the byte, and then mapping to non-blocking (using a custom combinator to emulate Incoming), or just operating directly on the raw FD.
Version
Platform
Linux xpanse 4.19.4-arch1-1-ARCH #1 SMP PREEMPT Fri Nov 23 09:06:58 UTC 2018 x86_64 GNU/Linux
Description
I have a tokio::net::TcpStream that was just yielded by .incoming(), and need to synchronously read a single byte from it immediately after the connection comes in. I currently do that (stupidly) using the code below. It works fine with
tokio 0.1.11
(playground), but ontokio 0.1.13
, it hangs forever as theread_exact
in the client never yields any bytes:strace
shows that theread_exact
after theaccept
never does any syscalls:With
tokio 0.1.11
, it shows:Notice in particular that in
tokio 0.1.11
, we havewhereas in
tokio 0.1.13
, thatrecvfrom
never appears.This may or may not be related to #774.
The text was updated successfully, but these errors were encountered: