One dropped packet left my keys stuck down
Part two of building nvx_kinetix, my KVM for Windows PCs: how a mouse, a keyboard and multi-gigabyte folders share one QUIC connection, and the one-line queue decision that left keys held down on the other machine.
By Ojas KekreCyber security, Monash University
In v1 of the input queue in nvx_kinetix, a full queue dropped the frame that had just arrived. Under load that frame was sometimes a key-up, and the key stayed held down on the other PC until I pressed it again.
- One 1-pixel mouse move
- 14 bytes
- Biggest input frame
- 23 bytes
- Of every key and button event
- 3 copies
- Of silence and the peer is gone
- 3 s
Part one ended with "The file bytes travel over QUIC with device-key pinning, which needs a write-up of its own". This is that, minus the parts I found boring.
One connection, two lanes
A KVM moves two very different things, and TCP gives you one ordered pipe. One lost packet freezes everything behind it, and a mouse waiting on a retransmit just feels frozen.
- 01
Mouse + keys
Tiny, constant, useless if late. Unreliable datagrams, so late means drop it
- 02
One UDP socket
TLS 1.3, both machines prove who they are
- 03
Clipboard + files
Very large, must arrive whole. Reliable streams, retransmit without blocking input
Machine identity
- 01
First run
Each machine makes an Ed25519 key
- 02
The key is its identity
No certificate authority
- 03
First meeting
You compare a short code on both screens
- 04
After that
The pinned key is the trust. Anything else gets refused
A mouse move is 14 bytes
- AVersion1 B
- BKind1 B
- CSequence2 B16-bit, wraps
- DTimestamp8 B
- Edx, dy2 BZigzag varints
The queue decision that broke keyboards
- 01Incoming input waits in a small queue before it is replayed on the other machine. The first version held 16 frames, and under load it fills. Input queue: queue 16/16.
- 02s to q: Key-up. A key-up arrives.
- 03The queue is full, so v1 drops the frame that just arrived. For a mouse that sounds harmless. Input queue: key-up dropped.
- 04For a keyboard it is not. The key stays held down on the other PC until you press it again. Picture Shift refusing to let go. Other PC: key held down.
Queue of 2,048, about a quarter second of an 8 kHz gaming mouse. A stale mouse move is the right thing to lose.
- 01s to r: Key-down x3. A key-down goes out three times, all with the same sequence number.
- 02The receiver keeps the first copy that shows up and applies it. Receiver: newest = key-down.
- 03s to r: Key-up x3. The key-up goes out the same way and is applied. Receiver: newest = key-up.
- 04s to r: Late key-down. A late copy of the key-down lands after the key-up. Applied, it would press the key again.
- 05It is older than the newest sequence the receiver has applied, so it is ignored. Receiver: late copy ignored.
Sequence numbers are 16-bit and wrap, so "older" needs wrapping maths.
1fn is_newer(seq: u16, last: u16) -> bool {
2 let ahead = seq.wrapping_sub(last);
3 ahead != 0 && ahead < 0x8000
4}- 1L265535 then 0 is one step forward, not 65,535 back.
- 2L3Less than half the range ahead counts as newer. Dupes and late arrivals fall outside.
- 1Same as the newest: ignored0
- Newer: applied1 to 32,767
- Older or late: ignored32,768 to 65,535
A dead peer or a quiet one
- v1
Pull the cable, wait out QUIC's long default
Your keyboard and mouse stay captured. Task Manager time.
- Fix 1
6 s idle timeout, 2 s keep-alive
Then healthy links dropped when nobody touched the mouse
- Fix 2
20 s idle, 2 runtime threads, 1 s app heartbeat
3 s of silence = gone. Release every held key first.
The second bug was in the runtime. With it on one thread, a single stall could delay the keep-alive long enough to lose the race against the idle timer. A quiet link is not a dead link, and it needs a heartbeat that isn't fighting for the same thread.
Folders bigger than memory
Each stream starts with a one-byte kind, and files stream off disk in 256 KiB chunks.
The receiver reads exactly the declared byte count for every file, even ones it rejects, so one bad filename can't desync the rest.
Names are treated as hostile: .., drive letters, alternate data streams, CON, NUL, and trailing dots and spaces, because Windows silently trims those and .. turns back into ...
My VMware adapter kept stealing the connection
192.168.0.213 real LAN 192.168.240.1 VMware host adapter <- sometimes dialled this dial 192.168.240.1 ... timed out
| Change | Detail |
|---|---|
| Which address to dial | Prefer an IPv4 on one of the dialling machine's own subnets. |
| Which adapters to advertise | Stop advertising adapters named like VMware, VirtualBox, Hyper-V, WSL or Docker. |
| Tailscale | Stays on, on purpose. People use it to reach their own boxes. |
Gaps
- 01Open
Resume
No resume yet. A dropped link restarts the transfer.
- 02Open
Latency numbers
None measured in the repo. The app shows QUIC's live round trip instead. Next to measure: p50/p99 input latency over Wi-Fi.
- 03Open
Network changes
A network change means re-link, not migrate.