Alex
Alex

Reputation: 619

How can I fix Resource temporarily unavailable error in Rust?

Here's an error log:

note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
        thread 'arbiter:724dcce3-b3b3-4523-8b02-3b2e9fa035dd:actix-net-worker-62' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }', src/libcore/result.rs:997:5

Here's my server setup:

let _ = server::new(move || {
        App::with_state()
            // Enable logger
            .middleware(middleware::Logger::default())
            .resource("/default", |r| HttpResponse::Ok)
    })
    .bind(&localhost_port)
    .unwrap_or_else(|_| panic!("Can not bind to {}", &localhost_port))
    .start();

I did look at another actix example which includes:

.shutdown_timeout(0)    // <- Set shutdown timeout to 0 seconds (default 60s)

but don't think it fix the issue for me.

Locally it runs OK, but this errors shows up when I execute a binary on Ubuntu 16.04.

Here's a related question: https://stackoverflow.com/a/14370767 that suggests to set a setting a send timeout with the SO_SNDTIMEO socket option.

Upvotes: 3

Views: 5631

Answers (1)

Jmb
Jmb

Reputation: 23453

Your issue isn't related to Rust (or Actix). Your problem is that some other program is already listening on the same port that you are trying to bind to. You need to identify which program it is, for example with:

sudo netstat -an --program | grep $PORT

(replacing $PORT with your port number), then kill that program or use another port.

Upvotes: 2

Related Questions