Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libnative does not close port cleanly under some circumstances #11835

Closed
derekchiang opened this issue Jan 27, 2014 · 6 comments
Closed

libnative does not close port cleanly under some circumstances #11835

derekchiang opened this issue Jan 27, 2014 · 6 comments
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows

Comments

@derekchiang
Copy link
Contributor

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
@derekchiang
Copy link
Contributor Author

Strangely though, if instead of using a browser you use curl, the problem doesn't happen.

@bnoordhuis
Copy link
Contributor

I think #11845 addresses this?

@alexcrichton
Copy link
Member

I would guess that #11845 is the fix, I'll test manually once it's merged.

@thestinger
Copy link
Contributor

Shouldn't it be calling shutdown regardless of whether it plans on reusing the port? I don't think SO_REUSEADDR if fixing the issue, just masking it.

@bnoordhuis
Copy link
Contributor

@thestinger shutdown() on a listen socket returns ENOTCONN. The issue here is the two minute grace time (or whatever the platform default is) for TCP ports.

@alexcrichton
Copy link
Member

Confirmed closed by #11845, thanks @xales!

flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 16, 2023
[`missing_asserts_for_indexing`]: accept length equality checks

Fixes rust-lang#11835

The lint now allows indexing with indices 0 and 1 when an `assert!(x.len() == 2);` is found.
(Also fixed a typo in the doc example)

changelog: [`missing_asserts_for_indexing`]: accept len equality checks as a valid assertion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
Projects
None yet
Development

No branches or pull requests

4 participants