hyper: Listening.close() does not close the server

I’m trying to run a hyper server, but after closing the guard, I can’t drop it and it hangs. Here’s some example code where it happens (sorry for the muda, was trying a ton of things)

fn request_temp_code() -> TempCode {
    Command::new("xdg-open").arg(format!("https://slack.com/oauth/authorize?client_id={}", SLACK_CLIENT_ID)).output().unwrap();
    let server = Server::http(Ipv4Addr(127, 0, 0, 1), 9999);

    let (tx, rx) = channel();
    let mtx = Mutex::new(tx);

    let mut guard = server.listen(move |req: Request, res: Response| {
        match req.uri {
            AbsolutePath(path) => {
                // Trying to manually drop to see if this is the problem
                let tempcode = extract_temp_code(&path).unwrap();
                let gmtx = mtx.lock().unwrap();
                gmtx.send(tempcode).unwrap();
                drop(gmtx);
            },
            _ => ()
        }

        let mut res = res.start().unwrap();
        res.write_all(b"Thanks! Please return to Lax").unwrap();
        res.end().unwrap();
    }).unwrap();

    let tempcode = rx.recv().unwrap();
    guard.close().unwrap();
    println!("{}", "Auth code received!");
    println!("{}", "Server closed!");
    // Hangs here
    tempcode
} 

I haven’t tried this with earlier versions of hyper (I think, not tracking numbers), however one of the last commits did involve changes related to the thread spawning into the acceptor. Have I found a possible bug?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 24 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I’m sorry but I don’t understand why this bug has been closed. The problem still exists right?

I am doing intergration test and spin up a new hyper server for each test. I use a pool of port number but the thing is that Hyper never release the port after being closed meaning that I can’t run all my tests…

The 0.10 branch is no longer seeing development. A way to shutdown servers that works is in 0.11. Fixing this is non trivial, and so likely won’t be fixed. If someone would like to submit a change that fixes this in 0.10, a new release could be made.