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

Request processing always times out, #694

Closed
silence-coding opened this issue Jun 15, 2023 · 1 comment
Closed

Request processing always times out, #694

silence-coding opened this issue Jun 15, 2023 · 1 comment

Comments

@silence-coding
Copy link
Contributor

silence-coding commented Jun 15, 2023

If the peer IP address is suddenly unreachable after the H2 client creates a connection and processes requests for a period of time, the request sent to the target domain name times out due to connection reuse. Is there any method to detect the IP address unreachability and create a new connection? In the Hyper Connector, each time a connection is created, the domain name is resolved again to obtain the IP address.

Keepalive has been configured.

            .http2_keep_alive_timeout(Duration::from_secs(10))
            .http2_keep_alive_while_idle(true)
            .http2_keep_alive_interval(Duration::from_secs(5));
impl<A: ToSocketAddrs + Send + Sync> TcpConnector<A> {
    async fn resolve(&self) -> io::Result<tokio::net::TcpStream> {
        let mut stream = Err(std::io::ErrorKind::AddrNotAvailable.into());
        let addr = { *self.addr_cache.read().unwrap() };
        if let Some(addr) = addr {
            stream = tokio::net::TcpStream::connect(addr).await;
        }
        if stream.is_err() {
            for addr in tokio::net::lookup_host(&self.addr).await? {
                match tokio::net::TcpStream::connect(addr).await {
                    Ok(s) => {
                        *self.addr_cache.write().unwrap() = Some(addr);
                        return Ok(s);
                    },
                    Err(e) => stream = Err(e),
                }
            }
        }
        stream
    }
}
@silence-coding
Copy link
Contributor Author

This is my code problem because the TcpStream::connect method keeps waiting

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

1 participant