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

Program gets stuck forever if tcp connect error happens #1256

Open
JakkuSakura opened this issue Apr 25, 2021 · 2 comments
Open

Program gets stuck forever if tcp connect error happens #1256

JakkuSakura opened this issue Apr 25, 2021 · 2 comments

Comments

@JakkuSakura
Copy link

The code is as followings. stream.binance.com is blocked in China. The thing is that there is no timeout by default, and the program just stay here forever trying to reconnect.

use tracing_log::LogTracer;
use tracing_subscriber::fmt;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing::Level;

pub fn setup_logs(log_level: Level) -> std::io::Result<()> {
    LogTracer::init().expect("Cannot setup_logs");
    let subscriber = fmt().with_max_level(log_level).with_thread_names(true).with_span_events(FmtSpan::CLOSE).finish();
    tracing::subscriber::set_global_default(subscriber).expect("Cannot setup_logs");
    Ok(())
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    setup_logs(Level::TRACE);
    let x = reqwest::get("https://stream.binance.com").await?.text().await?;
    println!("Result {}", x);
    Ok(())
}
Apr 25 21:54:26.492 TRACE main hyper::client::pool: checkout waiting for idle connection: ("https", stream.binance.com)
Apr 25 21:54:26.492 DEBUG main reqwest::connect: starting new connection: https://stream.binance.com/    
Apr 25 21:54:26.492 TRACE main hyper::client::connect::http: Http::connect; scheme=Some("https"), host=Some("stream.binance.com"), port=None
Apr 25 21:54:26.492 DEBUG tokio-runtime-worker hyper::client::connect::dns: resolving host="stream.binance.com"
Apr 25 21:54:26.498 DEBUG                 main hyper::client::connect::http: connecting to 45.114.11.238:443
Apr 25 21:54:26.498 TRACE                 main mio::poll: registering event source with poller: token=Token(1), interests=READABLE | WRITABLE    
Apr 25 21:54:26.800 DEBUG                 main hyper::client::connect::http: connecting to [2001::1f0d:5036]:443
Apr 25 21:54:26.800 TRACE                 main hyper::client::connect::http: connect error for [2001::1f0d:5036]:443: ConnectError("tcp connect error", Os { code: 101, kind: Other, message: "Network is unreachable" })

My debugger can only trace to hyper-0.14.5/src/client/client.rs:227.

    async fn send_request(
        &self,
        mut req: Request<B>,
        pool_key: PoolKey,
    ) -> Result<Response<Body>, ClientError<B>> {
 227:       let mut pooled = self.connection_for(pool_key).await?;

Maybe it's because retryably_send_request does not have a retry limit

@RdeWilde
Copy link

RdeWilde commented May 18, 2023

@qiujiangkun possibly running into the same problem. Did you ever find the root cause and/or find a way to fix it? Was it actually the missing retry limit?

@JakkuSakura
Copy link
Author

I tried to use proxies. It's a one time issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants