rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.98k stars 12.68k forks source link

fatal runtime error when using UnixListener with a BufferedStream #11688

Closed mvdnes closed 10 years ago

mvdnes commented 10 years ago

System

[user@vm-arch rust]$ uname -a
Linux vm-arch 3.12.7-2-ARCH #1 SMP PREEMPT Sun Jan 12 13:09:09 CET 2014 x86_64 GNU/Linux
[user@vm-arch rust]$ rustc -v
rustc 0.9
host: x86_64-unknown-linux-gnu

Description

The following code spawns a Unix Socket on /tmp/main.sock. Using nc -U /tmp/main.rs, the program responds with Incomming as expected. Pressing Ctrl-D, to issue an EOF, directly after connecting crashes the program. The issue does not occur when calling read_byte on the stream directly, or by using an TcpListener.

Code

use std::io::{Listener, Acceptor};
fn main() {
    let mut acceptor =  std::io::net::unix::UnixListener::bind(&Path::new("/tmp/main.sock")).listen().unwrap();
    println("Listening");
    for stream in acceptor.incoming() {
        do spawn {
            println("Incoming");
            std::io::buffered::BufferedStream::new(stream.unwrap()).read_byte();
        }
    }
}

Expected behaviour

No crash, maybe possibly an error message, but the application keeps on running.

Observed behaviour

netcat -U /tmp/main.sock
^D
Listening
Incoming

There are not many persons who know what wonders are opened to them in the
stories and visions of their youth; for when as children we listen and dream,
we think but half-formed thoughts, and when as men we try to remember, we are
dulled and prosaic with the poison of life. But some of us awake in the night
with strange phantasms of enchanted hills and gardens, of fountains that sing
in the sun, of golden cliffs overhanging murmuring seas, of plains that stretch
down to sleeping cities of bronze and stone, and of shadowy companies of heroes
that ride caparisoned white horses along the edges of thick forests; and then
we know that we have looked back through the ivory gates into that world of
wonder which was ours before we were wise and unhappy.

fatal runtime error:  assertion failed: !ptr.is_null()
Aborted (core dumped)
adrientetar commented 10 years ago

cc @alexcrichton

mvdnes commented 10 years ago

This issue seems to be fixed since read_byte() now returns a IoResult.