quinn-rs / quinn

Async-friendly QUIC implementation in Rust
Apache License 2.0
3.85k stars 394 forks source link

Is there any way to close the udp socket immediately? #1280

Closed juzi5201314 closed 2 years ago

juzi5201314 commented 2 years ago

After the endpoint is closed, the udp socket will not be closed immediately.If you start it immediately after closing the server, a port reuse error will occur.

I checked the source code and found that the socket is wrapped in Arc. Does EndpointInner drop after all connections are closed?

I tried calling Endpoint::close, but it didn't work. My current solution is to sleep for 3 seconds after Endpoint drop to ensure that the udp socket is closed.

Is there any way to ensure that the udp socket is closed?

Ralith commented 2 years ago

Dropping all references to an endpoint and its connections, including any pending futures. should cause the socket to close immediately.

NfNitLoop commented 2 years ago

My current solution is to sleep for 3 seconds after Endpoint drop to ensure that the udp socket is closed.

See: https://docs.rs/quinn/latest/quinn/struct.Endpoint.html#method.wait_idle

You can wait on that, and that should be significantly shorter than 3 seconds. :)

Ralith commented 2 years ago

It is not necessary to do that, though it is good manners.

Ralith commented 2 years ago

Closing for lack of response. Feel free to reopen with details if you're still having trouble with this.