Skip to content

Make zero-length Unix stream reads return without blocking or reporting EOF #990

Closed

Description

@LunaStev

Problem

unix_read always calls recv and interprets a zero result as EOF, even when the caller requested zero bytes. On Linux a zero-length recv on an empty blocking stream can wait for data; once data is queued it returns zero, which Wave incorrectly labels as peer closure. The TCP result and vectored helpers already distinguish zero-sized requests.

Starting point: unix_read.

Reproduction

Audited canonical master 540728c2eb6cc12f5c69c3fb3fdb96e07ba059a4 on Linux amd64 with a checkout-built Wave 0.0.1-alpha-dev, matching checkout std, Rust 1.89.0 and LLVM 21.1.8. Compile this at O0 and O2:

import("std::net::unix")::{UnixStream,unix_read};
import("std::net::error")::{NetIoResult};
fun main() -> i32 {
    var r: NetIoResult = unix_read(UnixStream { fd: 3 }, null, 0);
    println("count={} eof={} kind={}", r.count, r.eof, r.error.kind);
    return 0;
}

Execute from Python with an inherited local socketpair (descriptor 3 in this minimal harness):

import socket, subprocess
left, right = socket.socketpair()
try:
    assert left.fileno() == 3
    right.send(b'x')
    result = subprocess.run(['./repro'], pass_fds=(3,), capture_output=True,
                            text=True, timeout=2)
    print(result.stdout)
    print(left.recv(1))
finally:
    left.close()
    right.close()

Both optimization levels print count=0 eof=1 kind=10; the subsequent Python read still receives b'x' and the peer was never closed. Omitting the send made the subprocess hit the two-second timeout. No external communication was used.

Scope

Preserve invalid-size/buffer validation, then return a successful zero-count, non-EOF result without an OS read for size zero. Keep EOF behavior for nonempty reads after real peer closure. Difficulty: small localized change with a real socketpair regression.

Completion criteria

  • Zero-length reads return immediately with count 0, eof false and no error on an open empty stream.
  • Null buffers are allowed for zero bytes; negative sizes and nonempty null buffers remain invalid.
  • Queued data is preserved and real nonempty EOF still reports EOF at O0/O2.

Activity

  1. added
    bug
    good first issue
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions