Skip to content

Fix insane TTY input latency

Hanicef requested to merge Hanicef/SRB2:fix-insane-tty-latency into next

This has been a known issue to me for a long time, but it wasn't until recently since this has become a problem for me. In a nutshell, console input via TTY was capped to the game's ticrate, meaning that it only polled one character per tic. This effectively means if that if you do something that causes input to be typed faster than 35 characters per second, like pasting text into the terminal, the input is delayed by an insane amount - up to 10 seconds delay in certain situations!

This became a big problem for me when trying to integrate a screen session into the dedicated server build to automate server management with stuff like auto-restart when new changes have been detected upstream on the debug server. In this case, the server will notify this on the server by running the command say "Got new changes from upstream; server will update and restart shortly!", but since the update sequence was parallelized (emphasis on was), I ran into a race condition issue with the compilation stage where updates could be compiled faster than the message was being sent to the server, thus interleaving the quit command being sent afterwards with the restart command.

The solution to this is to poll for any input on the console and loop through all remaining input until all of it has been exhausted. That way, all input will be processed immediately and thus have a much smaller delay (haven't checked exactly, but it's in milliseconds now instead of seconds).

Merge request reports