emliunix / wsbrg.rs

A UDP relay over WebSocket
GNU General Public License v3.0
2 stars 0 forks source link

UdpSocket not properly closed after session termination #4

Open emliunix opened 4 years ago

emliunix commented 4 years ago

It's guaranteed that UdpSocket will release the resources when dropped. Eg. FileDesc::Drop() on unix platforms.

In my case, however, it's not dropped. I guess it's still kept somewhere in the async engine.

async fn handle_session() {
    let udp_port = tokio::net::UdpSocket::bind("...").await?;
    join!(other_task, handle_udp(udp_port))?;
}

how UdpSocket guaranteed to close on unix

The hierarchy is like:

emliunix commented 4 years ago

I think that's simply because the old session hasn't terminated in the first place. The session blocks at receiving next TCP message while the remote already exited.

And my CPU fan indicates the blocking must be some kind of loop.

emliunix commented 4 years ago

Seems it's still related to UdpSocket. After first UDP error, which is udp recv error, the CPU goes up to 100%. Inspect with a debugger shows it's stalled in UdpSocket::recv.

So the weired part is:

Maybe I can write a more clean code with only the UDP part to reproduce this issue.

And maybe I can stick to the principle that UDP receive error is unrecoverable.

emliunix commented 4 years ago

Sticking to the principle makes the program running normally. At least no CPU 100% in low-level code.

And now I need to figure out ways to manage my UDP connection. The problems are: