algesten / ureq

A simple, safe HTTP client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keep-alive is disabled when using SOCKS

HirbodBehnam opened this issue · comments

Hello
I've discovered that if you use socks5 proxy when building the Agent, ureq will instantiate a new connection for each request. However, when not using proxy, it will simply keep the connection and use the keep alive feature. I've also checked reqwest and apparently, that library does not have an issue and keeps the proxied connection alive.
I've written two small functions to test demonstrate it:

const SLEEP_TIME: Duration = Duration::from_secs(2);

fn test_ureq() {
    let agent = ureq::AgentBuilder::new()
        .proxy(ureq::Proxy::new("socks5://127.0.0.1:10818").unwrap())
        .build();
    for _ in 0..100 {
        println!("{}", agent.get("https://api.ipify.org/").call().unwrap().into_string().unwrap());
        thread::sleep(SLEEP_TIME);
    }
}

fn test_reqwest() {
    let client = reqwest::blocking::ClientBuilder::new()
        .proxy(reqwest::Proxy::all("socks5://127.0.0.1:10818").unwrap())
        .build()
        .unwrap();
    for _ in 0..100 {
        println!("{}", client.get("https://api.ipify.org/").send().unwrap().text().unwrap());
        thread::sleep(SLEEP_TIME);
    }
}

You can check it with wireshark to see that it instantiates a new connection for each request. Tested with reqwest 0.11.24 and ureq 2.9.4.

Hi @HirbodBehnam, welcome to ureq!

Thanks for reporting this. Must be something about the connection pooling that isn't happening under socks5.