Skip to content

What's the possible reason for server sending CONNECTION_REFUSED on handshake? #2234

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

Open
tubzby opened this issue May 12, 2025 · 6 comments

Comments

@tubzby
Copy link

tubzby commented May 12, 2025

Image

Everytime the client send a handshake the server responde with CONNECTION_REFUSED error.

@tubzby tubzby changed the title What's possible reason for server sending CONNECTION_REFUSED on handshake? What's the possible reason for server sending CONNECTION_REFUSED on handshake? May 12, 2025
@djc
Copy link
Member

djc commented May 12, 2025

Are you talking about a Quinn server? It looks like this could happen for one of three reasons:

  1. The configured number of connection identifiers is exhausted
  2. The server is full due to unprocessed packets
  3. The application rejected the connection

If this is your own server, I'm guessing it's (2) and you're forgetting to actively ignore or refuse connections that are coming in.

@tubzby
Copy link
Author

tubzby commented May 12, 2025

Yes, it's indeed an Quinn server, I have create an Quinn listener like this, what could be missing?

pub struct QAcceptor {
    ep: quinn::Endpoint,
    incoming: FuturesUnordered<quinn::IncomingFuture>,
}

impl QAcceptor {
    pub async fn accept<T: Sync + Send>(&mut self) -> anyhow::Result<QConn<T>>
    where
        T: QuicMsgType,
    {
        loop {
            tokio::select! {
                accepted = self.ep.accept() => {
                        if let Some(incoming) = accepted {
                            info!("accept: {}", incoming.remote_address());
                            self.incoming.push(incoming.into_future());
                        }
                }
                Some(conn) = self.incoming.next() => {
                    let conn = match conn {
                        Ok(x) => x,
                        Err(err) => {
                            error!("accept incoming error: {err:?}");
                            continue;
                        }
                    };
                    return Ok(QConn::new(conn, false).await?);
                },
            }
        }
    }
}

@djc
Copy link
Member

djc commented May 12, 2025

If I'm not mistaken, the conn from self.incoming.next() is an Incoming, not yet a Connection? So you should call .accept() on it.

@tubzby
Copy link
Author

tubzby commented May 12, 2025

From what I see calling incoming.into_future() will call Incoming.accept:

impl IntoFuture for Incoming {
    type Output = Result<Connection, ConnectionError>;
    type IntoFuture = IncomingFuture;

    fn into_future(self) -> Self::IntoFuture {
        IncomingFuture(self.accept())
    }
}

@djc
Copy link
Member

djc commented May 12, 2025

Okay, then I'm not sure what's going on and you might want to dig in.

@tubzby
Copy link
Author

tubzby commented May 12, 2025

Quite confused. I have been using code like this for a long time, and nothing happened.

Will switch to quinn::Connecting instead of quinn::IncomingFuture, seems more straightforward.

pub struct QAcceptor {
    ep: quinn::Endpoint,
    incoming: FuturesUnordered<quinn::Connecting>,
}

impl QAcceptor {
    pub async fn accept<T: Sync + Send>(&mut self) -> anyhow::Result<QConn<T>>
    where
        T: QuicMsgType,
    {
        loop {
            tokio::select! {
            accepted = self.ep.accept() => {
                if let Some(incoming) = accepted {
                    info!("accept: {}", incoming.remote_address());
                    let connecting = match incoming.accept() {
                        Ok(x) => x,
                        Err(err) => {
                            error!("accept incoming error: {}", err);
                            continue;
                        }
                    };
                    self.incoming.push(connecting);
                }
            }
                Some(conn) = self.incoming.next() => {
                    let conn = match conn {
                        Ok(x) => x,
                        Err(err) => {
                            error!("accept incoming error: {err:?}");
                            continue;
                        }
                    };
                    return Ok(QConn::new(conn, false).await?);
                },
            }
        }
    }
}

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