Adam Shiervani 203c6ae6fd fix: recover HID chardev after DWC3 rebind race on RV1106 (#1366)
* fix: reset USB gadget when virtual media unmount fails with EBUSY (#834)

When unmountImageLocked() gets EBUSY from the kernel (host OS still
accessing the virtual disk via PREVENT MEDIUM REMOVAL), fall back to
gadget.RebindUsb(true) to force-disconnect the host, then retry the
unmount. Uses RebindUsb directly instead of UpdateGadgetConfig to avoid
hitting the same EBUSY when writing configfs attributes before rebind.

After rebind, properly reopen keyboard HID file (ResetHIDFiles + sleep +
OpenKeyboardHidFile) matching the pattern in setMassStorageMode().

Also propagate unmount errors to RPC callers and only clear
currentVirtualMediaState after the unmount actually succeeds.

Adds E2E test that mounts an ISO on the remote host to trigger PREVENT
MEDIUM REMOVAL, then verifies unmount succeeds and keyboard recovers.

* fix: recover HID chardev after DWC3 rebind race on RV1106

The DWC3 USB controller on the RV1106 has a race condition where rapid
unbind→bind of the UDC can permanently corrupt HID chardev state —
/dev/hidg0 returns ENXIO even though the device node exists and the UDC
shows "configured". This can be triggered by UpdateGadgetConfig's
transaction rebind and by host-initiated USB device resets during mass
storage media changes.

Three-part fix:

1. rebindUsb(): after binding, verify /dev/hidg0 is openable. If not,
   unbind again with a 100ms pause for kernel cleanup, then rebind.

2. setMassStorageMode(): pre-set recovery timer before UpdateGadgetConfig
   to prevent the poller from interfering. After the 1s sleep, if
   OpenKeyboardHidFile fails, do a corrective RebindUsb + retry.

3. checkUSBState() poller: when a state transition occurs and
   OpenKeyboardHidFile fails, trigger a corrective rebind to recover
   from host-initiated USB resets that corrupt the chardev.

* fix: suppress USB recovery poller before rebind in unmount and mode-change paths

The auto-recovery poller could see transient "not attached" UDC state
during RebindUsb and trigger a competing rebind, corrupting HID chardev
state. Add setUSBRecoveryTimer calls before the rebind in
unmountImageLocked and before the corrective rebind in setMassStorageMode.

* test: replace blind sleep with two-phase wait in factory-reset e2e test

Wait for device to become unreachable before polling for it to come back,
preventing false passes from stale pre-reset responses.

* refactor: simplify branch — extract helpers, remove duplication, fix flaky tests

- Extract rebindAndRecoverHID() in Go to deduplicate USB recovery sequences
- Remove redundant setUSBRecoveryTimer() call after UpdateGadgetConfig()
- Extract waitForKeyboardReady() helper replacing 5 duplicate retry loops
- Consolidate 3 duplicate remoteExec definitions into single remoteHostExec()
- Use shared SSH_OPTS from helpers.ts instead of hardcoded SSH options
- Fix remote agent omitempty on mouse X/Y causing undefined in TypeScript
- Poll keys-down state in disconnect test to avoid race condition

* fix: remove dead IsHidgChardevHealthy export, reset HID files before rebind

- Remove unused exported IsHidgChardevHealthy wrapper (only the unexported
  isHidgChardevHealthy is called, inside rebindUsb)
- Move ResetHIDFiles() before RebindUsb in checkUSBState so stale file
  handles are closed even if the rebind fails — prevents silent mouse
  write failures on dead inodes after a successful unbind + failed bind
2026-03-28 20:56:21 +01:00
2024-12-29 21:27:42 +01:00
2025-09-29 14:09:30 +02:00
2026-03-05 18:26:23 +01:00
2024-12-29 21:27:42 +01:00
2025-09-29 14:09:30 +02:00
2026-01-28 09:19:56 +01:00
2025-09-29 14:09:30 +02:00
2026-01-28 09:19:56 +01:00
2026-01-28 09:19:56 +01:00
2024-12-29 21:27:42 +01:00
2025-10-15 18:32:58 +02:00
2025-03-26 18:41:09 +01:00
2025-04-11 00:43:45 +02:00
2026-02-08 10:19:28 +01:00
2025-09-29 14:09:30 +02:00
2026-01-28 09:19:56 +01:00

JetKVM is a high-performance, open-source KVM over IP (Keyboard, Video, Mouse) solution designed for efficient remote management of computers, servers, and workstations. Whether you're dealing with boot failures, installing a new operating system, adjusting BIOS settings, or simply taking control of a machine from afar, JetKVM provides the tools to get it done effectively.

Features

  • Ultra-low Latency - 1080p@60FPS video with 30-60ms latency using H.264 encoding. Smooth mouse and keyboard interaction for responsive remote control.
  • Free & Optional Remote Access - Remote management via JetKVM Cloud using WebRTC.
  • Optional Tailscale Networking - Built-in Tailscale status and control-server configuration, including custom Headscale-compatible endpoints.
  • Open-source software - Written in Golang on Linux. Easily customizable through SSH access to the JetKVM device.

Contributing

We welcome contributions from the community! Whether it's improving the firmware, adding new features, or enhancing documentation, your input is valuable. We also have some rules and taboos here, so please read this page and our Code of Conduct carefully.

I need help

The best place to search for answers is our Documentation. If you can't find the answer there, check our Discord Server.

I want to report an issue

If you've found an issue and want to report it, please check our Issues page. Make sure the description contains information about the firmware version you're using, your platform, and a clear explanation of the steps to reproduce the issue.

Development

JetKVM is written in Go & TypeScript. with some bits and pieces written in C. An intermediate level of Go & TypeScript knowledge is recommended for comfortable programming.

The project contains two main parts, the backend software that runs on the KVM device and the frontend software that is served by the KVM device, and also the cloud.

For comprehensive development information, including setup, testing, debugging, and contribution guidelines, see DEVELOPMENT.md.

For quick device development, use the ./dev_deploy.sh script. It will build the frontend and backend and deploy them to the local KVM device. Run ./dev_deploy.sh --help for more information.

Backend

The backend is written in Go and is responsible for the KVM device management, the cloud API and the cloud web.

Frontend

The frontend is written in React and TypeScript and is served by the KVM device. It has three build targets: device, development and production. Development is used for development of the cloud version on your local machine, device is used for building the frontend for the KVM device and production is used for building the frontend for the cloud.

S
Description
JetKVM - Control any computer remotely
kvm
Readme GPL-2.0 39 MiB
Languages
TypeScript 36.2%
C 35.3%
Go 25.8%
Shell 0.9%
Makefile 0.6%
Other 1%