{"record":{"id":"6bfcdbd348e664d8","repo":"tokio-rs/tokio","slug":"not-in-o-rdonly-or-o-rdwr-access-mode","errorCode":null,"errorMessage":"not in O_RDONLY or O_RDWR access mode","messagePattern":"not in O_RDONLY or O_RDWR access mode","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"tokio/src/net/unix/pipe.rs","lineNumber":977,"sourceCode":"    /// # Panics\n    ///\n    /// This function panics if it is not called from within a runtime with\n    /// IO enabled.\n    ///\n    /// The runtime is usually set implicitly when this function is called\n    /// from a future driven by a tokio runtime, otherwise runtime can be set\n    /// explicitly with [`Runtime::enter`](crate::runtime::Runtime::enter) function.\n    pub fn from_owned_fd(owned_fd: OwnedFd) -> io::Result<Receiver> {\n        if !is_pipe(owned_fd.as_fd())? {\n            return Err(io::Error::new(io::ErrorKind::InvalidInput, \"not a pipe\"));\n        }\n\n        let flags = get_file_flags(owned_fd.as_fd())?;\n        if has_read_access(flags) {\n            set_nonblocking(owned_fd.as_fd(), flags)?;\n            Receiver::from_owned_fd_unchecked(owned_fd)\n        } else {\n            Err(io::Error::new(\n                io::ErrorKind::InvalidInput,\n                \"not in O_RDONLY or O_RDWR access mode\",\n            ))\n        }\n    }\n\n    /// Creates a new `Receiver` from a [`File`] without checking pipe properties.\n    ///\n    /// This function is intended to construct a pipe from a File representing\n    /// a special FIFO file. The conversion assumes nothing about the underlying\n    /// file; it is left up to the user to make sure it is opened with read access,\n    /// represents a pipe and is set in non-blocking mode.\n    ///\n    /// # Examples\n    ///\n    /// ```no_run\n    /// use tokio::net::unix::pipe;\n    /// use std::fs::OpenOptions;","sourceCodeStart":959,"sourceCodeEnd":995,"githubUrl":"https://github.com/tokio-rs/tokio/blob/625954f365727668cb02d04172b34f1149637728/tokio/src/net/unix/pipe.rs#L959-L995","documentation":"Receiver::from_owned_fd's second guard: after confirming the fd is a pipe, it checks has_read_access on the file flags; without O_RDONLY or O_RDWR it errors InvalidInput 'not in O_RDONLY or O_RDWR access mode'. You cannot wrap a write-only pipe end as a Receiver.","triggerScenarios":"Calling Receiver::from_owned_fd with a pipe fd opened write-only (O_WRONLY) — typically the write end of a pipe pair.","commonSituations":"Passing the wrong end of pipe() to Receiver; opening a FIFO with O_WRONLY and trying to receive; confusing the directionality of a pipe pair.","solutions":["Pass the read end of the pipe pair to Receiver::from_owned_fd.","Open the FIFO with read access if you intend to receive.","Check getfl for the access mode and route to Sender vs Receiver accordingly.","Use os_pipe::pipe() or tokio's pipe() so the ends are correctly typed from creation."],"exampleFix":"// before\nlet (read, write) = os_pipe::pipe()?;\nlet r = Receiver::from_owned_fd(write)?; // wrong end\n\n// after\nlet (read, write) = os_pipe::pipe()?;\nlet r = Receiver::from_owned_fd(read)?;\nlet s = Sender::from_owned_fd(write)?;","handlingStrategy":"validation","validationCode":"use nix::fcntl::{fcntl, Fcntl, FcntlFlag};\nuse std::os::unix::io::AsRawFd;\nlet flags = FcntlFlag::from_bits_truncate(fcntl(fd.as_raw_fd(), Fcntl::F_GETFL)?);\nif !flags.intersects(FcntlFlag::O_RDONLY | FcntlFlag::O_RDWR) {\n    return Err(anyhow::anyhow!(\"fd not opened for reading\"));\n}\nReceiver::from_owned_fd(fd)?;","typeGuard":"fn is_not_readable(e: &io::Error) -> bool {\n    e.kind() == io::ErrorKind::InvalidInput && e.to_string().contains(\"O_RDONLY\")\n}","tryCatchPattern":"match Receiver::from_owned_fd(fd) {\n    Ok(r) => Ok(r),\n    Err(e) if e.to_string().contains(\"access mode\") => {\n        Err(anyhow::anyhow!(\"fd is write-only; pass the read end of the pipe\"))\n    }\n    Err(e) => Err(e.into()),\n}","preventionTips":["Pass the read end of pipe() to Receiver::from_owned_fd.","Open FIFOs intended for receiving with read access and O_NONBLOCK.","Check F_GETFL for the access mode before wrapping.","Use os_pipe::pipe or tokio's pipe() so ends are typed from creation."],"tags":["unix","pipe","fd","access-mode","receiver","tokio"],"backgroundTag":null,"analyzedSha":"625954f365727668cb02d04172b34f1149637728","analyzedAt":"2026-08-11T17:46:45.378Z","contentChangedAt":"2026-08-11T17:46:45.378Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}