quinn-rs / quinn

Async-friendly QUIC implementation in Rust
Apache License 2.0
3.76k stars 380 forks source link

close conn is crash on cross compile to android #1586

Closed centny closed 1 year ago

centny commented 1 year ago
image

connect

  let addr = remote.trim_start_matches("quic://").to_string();
  let domain: &String = json_option_str(&option, "domain").unwrap_or(&addr);
  let addr_conn = wrap_err(addr.parse())?;
  let runtime = quinn::default_runtime().ok_or_else(|| new_message_err("no async runtime found"))?;
  let mut endpoint = quinn::Endpoint::new(quinn::EndpointConfig::default(), None, conn, runtime)?;
  let tls = load_tls_config(self.dir.clone(), &option)?;
  endpoint.set_default_client_config(quinn::ClientConfig::new(tls));
  let conn = wrap_err(endpoint.connect(addr_conn, domain))?.await?;
  let (send, recv) = conn.open_bi().await?;
  let (rx, tx) = wrap_quinn_w(send, recv);
Ralith commented 1 year ago

Please include terminal output and trace logs.

centny commented 1 year ago

found the reason, the send be closed twice. is it a issue? std tcp stream cant be close multi time

Ralith commented 1 year ago

Quinn shouldn't panic. Can you provide a minimal reproduction?

centny commented 1 year ago

yesterday,i split the minimal code and create test project to find the issue. uploaded to testquinncrash, follow readme, it can reproduce it.

now, i avoid it by add closed check.

pub struct WrapQuinnWriter {
    inner: quinn::SendStream,
    closed: bool,
}

#[async_trait]
impl RawWriter for WrapQuinnWriter {
    async fn write(&mut self, buf: &[u8]) -> tokio::io::Result<usize> {
        self.inner.write_all(buf).await?;
        self.inner.flush().await?;
        Ok(buf.len())
    }
    async fn shutdown(&mut self) {
        // not check close will be crash
        // if self.closed {
        //     return;
        // }
        self.closed = true;
        _ = self.inner.shutdown().await;
    }
}
Ralith commented 1 year ago

I think this is a duplicate of https://github.com/quinn-rs/quinn/issues/1569. There's a fix drafted at https://github.com/quinn-rs/quinn/pull/1575.