quinn-rs / quinn

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

Await connection drain #1665

Open BiagioFesta opened 1 year ago

BiagioFesta commented 1 year ago

I am wondering if it mighty worth it to have a future to await the draining of the connection (if such possibility does not exist yet).

The scenario is the following:

async fn main() {
   // ...
   connection.close(VarInt::from_u32(0), b"bye");
}

The CLOSE frame might not be sent if program terminates before driver flushes egress.

On top of my head, I was thinking something like:

connection.close(...);
connection.drained().await;  // Awaits flush egress

Feel free to close this issue in case, it is just a very minor concern :)

djc commented 1 year ago

Call wait_idle() on the Endpoint? Or do you specifically need this for a connection only?

https://github.com/quinn-rs/quinn/blob/main/quinn/src/endpoint.rs#L283C1-L283C1 ?

BiagioFesta commented 1 year ago

Nice, I was not aware about that method on Endpoint.

I guess that might perfectly work as well.

Thanks

BiagioFesta commented 1 year ago

Anyway, could it maybe be interesting to have also on Connection as client code might easily drop the endpoint. Or cleanup a single connection from server.