Skip to content

Reading from named pipe seems limited to 4096 bytes #5307

@LeonarddeR

Description

@LeonarddeR

Version
tokio v1.23.0

Platform
Windows 11 64-bit

Description
I'm using Tokio as a named pipe server. However, when reading data from a pipe, I"m only getting chunks with a max of 4096 bytes, even though my vector has a higher capacity.

I tried this code:

        ASYNC_RUNTIME.spawn(async move {
            let mut first_pipe_instance = true;
            loop {
                trace!("Creating pipe server with address {}", pipe_addr);
                let server = ServerOptions::new()
                    .first_pipe_instance(first_pipe_instance)
                    .max_instances(1)
                    .create(&pipe_addr)
                    .unwrap();
                first_pipe_instance = false;
                trace!("Initiate connection to pipe client");
                server.connect().await.unwrap();
                let (mut server_reader, server_writer) = split(server);
                trace!("Pipe client connected. Initiating pipe_reader loop");
                loop {
                    let mut buf = Vec::with_capacity(1024 * 64);
                    match server_reader.read_buf(&mut buf).await {
                        Ok(0) => {
                            info!("Received 0 bytes, pipe closed by client");
                            break;
                        }
                        Ok(n) => {
                            trace!("read {} bytes", n);
                        }
                        Err(e) if e.kind() == WouldBlock => {
                            warn!("Reading pipe would block: {}", e);
                            continue;
                        }
                        Err(e) => {
                            error!("Error reading from pipe server: {}", e);
                            break;
                        }
                    }
                }
            }
        })

I expected to see this happen: When connecting to this pipe from a client and sending a message of 8192 bytes, I'd expect a message of 8192 bytes coming in at the sever's end.

Instead, this happened: The message came in as two chunks of 4096 bytes in size. It seems like there is a hard limit of 4096 bytes somewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-bugCategory: This is a bug.M-netModule: tokio/net

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions