actix-web: bug: actix_web client unable to connect to any host on windows

Following example code always produces Error: Connect(Timeout):

use actix_rt::System;
use awc::Client;
use futures::future::{
    Future,
    lazy
};

fn main() {
    System::new("weight_version").block_on(lazy(|| {

        awc::Client::new().get("https://google.com") //any address here
            .header("User-Agent", "Actix-web")
            .send()
            .map_err(|error| {
                println!("Error: {:?}", error);
            })
            .and_then(|response| {
                println!("Response: {:?}", response);
                Ok(())
            })
    }));
}

actix_web::client::Client also produces same error:

use actix_rt::System;
use actix_web::client::Client;
use futures::future::{
    Future,
    lazy
};

fn main() {
    System::new("weight_version").block_on(lazy(|| {
        let client = Client::default();

        client.get("https://www.rust-lang.org/")
            .header("User-Agent", "Actix-web")
            .send()
            .map_err(|error| {
                println!("Error: {:?}", error);
                //Err(error)
            })
            .and_then(|response| {
                println!("Response: {:?}", response);
                Ok(())
            })
    }));
}

Tested on 3 totally different windows machines with following:

openssl version
OpenSSL 1.1.1c  28 May 2019

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 38 (10 by maintainers)

Most upvoted comments

I have the same issue on my windows system while the same code works perfectly fine on linux.

 awc::Client::build()
            .connector(
                awc::Connector::new()
                    .timeout(Duration::from_secs(10))
                    .finish(),
            )
            .timeout(Duration::from_secs(10))
            .finish()

I got it work by construct client this way but I still get very poor response time.

add rustls feature works fine

@Bhaal22 exactly the same for me:

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.15.3
BuildVersion:	19D76

very odd…

@rokit not quite, I’m just making a single request, using the actix-web async client (the request is to an endpoint that just fetches a fast responding web page). When using the actix-web HTTP client on Mac OS X, and in a debug build, I get a connect timeout error. In a release build, it works fine.

I’m using reqwest and web::block as a workaround for the actix-web client issue (request + block works fine).

I’ve been getting the same error/behaviour on Mac OS X as well (the same code works fine on Linux for me).

The issue only seems to occur on debug builds too (perhaps because the request takes longer and times out?). Running under a release build works fine.

In case it’s of any use, this is the trace log output from my server. My server is just:

use actix_web::{client::Client, web, App, HttpResponse, HttpServer, Error};
use futures::Future;

fn index() -> impl Future<Item = HttpResponse, Error = Error> {
    let client = Client::default();
    client.get("http://example.com")
        .send()
        .map_err(Error::from)
        .and_then(|mut resp| {
            resp.body()
                .from_err()
                .and_then(|body| {
                    Ok(HttpResponse::Ok().body(body))
                })
        })
}

fn main() {
    env_logger::init();
    HttpServer::new(|| {
        App::new()
            .route("/", web::get().to_async(index))
    })
        .bind("127.0.0.1:8088")
        .unwrap()
        .run()
        .unwrap();
}

and the trace logging output:

[2019-08-21T11:16:17Z TRACE tokio_reactor] event Readable Token(4194303)
[2019-08-21T11:16:17Z TRACE tokio_reactor] loop process - 1 events, 0.000s
[2019-08-21T11:16:17Z TRACE tokio_reactor] event Readable Token(4194303)
[2019-08-21T11:16:17Z TRACE tokio_reactor] loop process - 1 events, 0.000s
[2019-08-21T11:16:17Z DEBUG tokio_reactor] adding I/O source: 0
[2019-08-21T11:16:17Z TRACE mio::poll] registering with poller
[2019-08-21T11:16:17Z TRACE mio::sys::unix::kqueue] registering; token=Token(0); interests=Readable | Writable | Error | Hup
[2019-08-21T11:16:17Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-08-21T11:16:17Z TRACE tokio_reactor] event Readable | Writable Token(0)
[2019-08-21T11:16:17Z TRACE tokio_reactor] loop process - 1 events, 0.000s
[2019-08-21T11:16:17Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-08-21T11:16:17Z TRACE actix_connect::resolver] DNS resolver: resolving host "example.com"
[2019-08-21T11:16:17Z TRACE tokio_reactor] event Readable Token(4194303)
[2019-08-21T11:16:17Z TRACE tokio_reactor] loop process - 1 events, 0.000s
[2019-08-21T11:16:17Z DEBUG trust_dns_resolver::async_resolver::background] trust-dns resolver running
[2019-08-21T11:16:26Z TRACE tokio_reactor] event Readable Token(4194303)
[2019-08-21T11:16:26Z TRACE tokio_reactor] loop process - 1 events, 0.000s
[2019-08-21T11:16:26Z DEBUG tokio_reactor::registration] scheduling Read for: 0
[2019-08-21T11:16:26Z DEBUG trust_dns_proto::xfer::dns_handle] querying: example.com A
[2019-08-21T11:16:26Z TRACE tokio_reactor] event Writable Token(0)
[2019-08-21T11:16:26Z TRACE tokio_reactor] event Readable Token(4194303)
[2019-08-21T11:16:26Z TRACE tokio_reactor] loop process - 2 events, 0.000s
[2019-08-21T11:16:26Z TRACE actix_http::h1::dispatcher] Keep-alive timeout, close connection
[2019-08-21T11:16:26Z TRACE mio::poll] deregistering handle with poller
[2019-08-21T11:16:26Z DEBUG tokio_reactor] dropping I/O source: 0
[2019-08-21T11:16:26Z TRACE tokio_reactor] loop process - 0 events, 0.000s