OpenOptions::open never returns #7095
-
I have this function here which creates a UNIX named pipe for writing: use std::path::Path;
use std::io;
use nix::sys::stat;
use nix::unistd;
async fn create_and_open_named_pipe(path: &Path) -> io::Result<tokio::fs::File> {
println!("Creating pipe...");
unistd::mkfifo(path, stat::Mode::S_IRUSR | stat::Mode::S_IWUSR)
.expect("Failed to create FIFO");
println!("Opening pipe...");
let file = tokio::fs::OpenOptions::new()
.write(true)
.open(path)
.await;
println!("done"); // Never prints
file
} But it blocks indefinitely around |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
From
|
Beta Was this translation helpful? Give feedback.
-
Do not use |
Beta Was this translation helpful? Give feedback.
-
Thanks. I rewrote the function: fn create_and_open_named_pipe(path: &Path) -> tokio::net::unix::pipe::Sender {
unistd::mkfifo(path, stat::Mode::S_IRUSR | stat::Mode::S_IWUSR)
.expect("Failed to create FIFO");
// source: https://docs.rs/tokio/latest/tokio/net/unix/pipe/struct.OpenOptions.html
tokio::net::unix::pipe::OpenOptions::new()
.read_write(true)
.unchecked(true)
.open_sender(path)
.expect("Failed to open FIFO")
} But now instead of blocking there, it blocks at a later 'copy' call: let mut sender = create_and_open_named_pipe(path);
tokio::io::copy(&mut reader, &mut sender).await.unwrap();
// (send command to child process to make it read the FIFO)
self.send(path).await.unwrap() Which makes sense with what sfackler said because the receiving end isn't configured yet. Does tokio provides anything to fix that? |
Beta Was this translation helpful? Give feedback.
Do not use
tokio::fs
with things that are not real files. Please seetokio::net::unix::pipe
for utilities for working with fifo pipes from Tokio.