Skip to content

libnative does not close port cleanly under some circumstances #11835

Closed
@derekchiang

Description

@derekchiang

Machine: Ubuntu 13.10, 64-bit

rustc version: 0.10-pre (master)

Steps to reproduce:

  1. Compile this code:
extern mod native;

use std::io::{io_error, Listener, Acceptor};
use std::io::net::ip::SocketAddr;
use std::io::net::tcp::{TcpListener};

#[start]
fn start(argc: int, argv: **u8) -> int {
    do native::start(argc, argv) {
        let mut acceptor = match TcpListener::bind(
            from_str::<SocketAddr>("127.0.0.1:8021").unwrap()).listen() {
            None => {
                error!("bind or listen failed :-(");
                return;
            },
            Some(acceptor) => acceptor,
        };

        let mut error = None;
        io_error::cond.trap(|e| {
            error = Some(e);
        }).inside(|| {
            println!("Visit http://127.0.0.1:8021");
            acceptor.accept();
            println!("Got a stream!");
        });
    }
}
  1. Run the executable.
  2. Visit http://127.0.0.1:8021 in a browser (the program will terminate).
  3. Run the executable again.

Now you should see a task failure like this:

task '<unnamed>' failed at 'Unhandled condition: io_error: io::IoError{kind: ConnectionRefused, desc: "address in use", detail: Some(~"Address already in use")}', /build/buildd/rust-nightly-201401260405~897a0a3~saucy/src/libstd/condition.rs:139

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions