htrefil / rkvm

Virtual KVM switch for Linux machines
MIT License
415 stars 51 forks source link

rkvm-{server,client}: Remove dead peers quickly #44

Closed ckiee closed 1 year ago

ckiee commented 1 year ago

I use rkvm on a machine which hangs multiple times a day, leaving no TCP FIN or RSTs behind.

Previously, the UX got very confusing once I rebooted the machine, because it captured inputs without forwarding them anywhere live.

It's unfortunate that the TCP settings aren't shared between the client & server because keepalive settings should be consistent to avoid one peer disconnecting and the other waiting longer before timing out.

htrefil commented 1 year ago

Very nice, this has been annoying me for a while too. Sorry that it didn't make it to 0.4.0, I missed your PR.

Just curious - why did you choose the values you did? With these changes in, if I suspend my client machine, how long will it take for the server to notice and disconnect it?

ckiee commented 1 year ago

ref: https://docs.rs/socket2/latest/socket2/struct.TcpKeepalive.html

If nothing's been sent in the last second, we send a keepalive and wait 10 seconds before timing out or sending another one. We also retry once just in case, but my x86_64-linux system seemingly doesn't do this; maybe that should be set to zero.

It does take a few seconds for all of that to happen from the server's POV but I figured that's better than random disconnections with bad network conditions.

wireshark capture showing a few good keepalives and then one with no response

On my client system it converges with the server, sending it a RST back (It never got the client's RST, since it was suspended) and after a mysterious ~5 seconds it dials the server back up.