Skip to content

Conversation

@IDisposable
Copy link
Contributor

Fixes #128

Summary

  • Revamped the polling and writing of the USB gadget to correct for dropped connections
  • Corrected the initialization order to ensure we run even if the USB is disconnected (and we're getting power from the y-splitter/POE)
  • Ensured that we restart the LED listening polling
  • If we exceed too many consecutive write errors, close and reopen the gadget

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 42 out of 42 changed files in this pull request and generated 17 comments.

Comments suppressed due to low confidence (2)

internal/usbgadget/usbgadget.go:185

  • File handle may be writable as a result of data flow from a call to OpenFile and closing it may result in data loss upon failure, which is not handled explicitly.
		u.absMouseHidFile.Close()

internal/usbgadget/usbgadget.go:189

  • File handle may be writable as a result of data flow from a call to OpenFile and closing it may result in data loss upon failure, which is not handled explicitly.
		u.relMouseHidFile.Close()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@IDisposable IDisposable force-pushed the fix/usb-gadget branch 2 times, most recently from 6bdbca4 to 96d7189 Compare December 11, 2025 19:22
Copy link
Contributor

@adamshiervani adamshiervani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LED state synchronization stops working after 1-2 runs of make test_e2e. The keyboard and mouse movement both work, it's just the LED state that stops updating. A restart fixes the issue.

Also, worth mentioning is that I can also reproduce this issue latest dev without this PR.

@IDisposable
Copy link
Contributor Author

I will look into the LED state issue. When you say it "stops working" do you mean that the client doesn't track the server state, or do you mean the UI doesn't track the RPC pushes?

@adamshiervani
Copy link
Contributor

The remote host receives all keys and mouse events, it's just that the UI doesn't properly reflect the LED State. This makes the make test_e2e fail, as it uses the LED State to determine whether the remote host handles keyboard presses.

@IDisposable
Copy link
Contributor Author

The remote host receives all keys and mouse events, it's just that the UI doesn't properly reflect the LED State. This makes the make test_e2e fail, as it uses the LED State to determine whether the remote host handles keyboard presses.

I'll dig in this weekend... what LED state are we tracking, and what is the test JetKVM physically attached to on the USB port? I notice that MacOS doesn't light the CapsLock LED as I would expect (never really has...) Do you know what kind of machine the Jet is driving?

@adamshiervani
Copy link
Contributor

The remote host i'm testing on is on Ubuntu 24.04.

@IDisposable IDisposable force-pushed the fix/usb-gadget branch 2 times, most recently from 960e70b to 624408f Compare December 22, 2025 22:09
@IDisposable
Copy link
Contributor Author

IDisposable commented Dec 23, 2025

So I did a few things:

  • Switched the push-based LED state reporting to follow the same pattern as the pushed key-down state reporting to use a channel so that we won't block when trying to send back the LED state
  • Added an OverwriteChan go chan wrapper that discards the oldest entry when asked to queue something and the channel is full
  • Switch both LED and key-down state reporting channels to use the OverwriteChan such that when we start a session, the channels get initialized with a limit of 4 (for LED) and 16 (for key-down) pending messages... if we have more backed up, the oldest one(s) get discarded and the channel is never full. I suspect that both of those limits are much higher than needed (probably only need most recent one).
  • Updated the devices.$id.tsx to always ask for LED and key-down state at route load, and setup a 30-second polling for state in case we miss the state being pushed.
  • Removed the LED "Shift" state as that was not reliable across machines

@adamshiervani
Copy link
Contributor

Updated the devices.$id.tsx to always ask for LED and key-down state at route load, and setup a 30-second polling for state in case we miss the state being pushed.

This feels like something is broken. Any special reason for this?

@IDisposable
Copy link
Contributor Author

IDisposable commented Dec 29, 2025

Updated the devices.$id.tsx to always ask for LED and key-down state at route load, and setup a 30-second polling for state in case we miss the state being pushed.

This feels like something is broken. Any special reason for this?

Honestly, this was to address your observation that we were failing occasionally to track the LED state in E2E. I didn't really ever see that, but put this in as a backup plan. We could not do it at all, or change the poll rate.

@adamshiervani
Copy link
Contributor

This does not resolve issue #128 for me on an Ubuntu 24 remote host.

Steps to reproduce:

  1. Start the JetKVM without a USB cable connected, powering it only via the DC extensions through the RJ-12 port.
  2. Wait for the device to finish booting.
  3. Plug in the USB cable.

Result:
The USB status remains “Disconnected,” and both the keyboard and mouse fail to function.

@IDisposable
Copy link
Contributor Author

I'm powering from the USB splitter (power side going to a dumb USB charger) plugging the USB data-side of the splitter into a MacBook after it and the JetKVM are fully booted. Shows the USB connected and the mouse and keyboard work without power any settings/reboots. So strange.

@adamshiervani
Copy link
Contributor

That's so odd. Do you have an DC or ATX extension available to test my setup?

Also, I'm getting a null pointer when disabling all the USB Devices.

2026-01-06T13:35:00Z ERR jetkvm jsonrpc Error calling RPC handler error="runtime error: invalid memory address or nil pointer dereference" id=12 length=157 method=setUsbDevices params={"devices":{"absolute_mouse":false,"keyboard":false,"mass_storage":false,"relative_mouse":false}}
2026-01-06T13:35:02Z INF jetkvm gin Request body_size=16 ip=192.168.1.40 latency=0.1785 method=GET path=/device/status status=200 user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36"```

Once fixed, could you also make an e2e test for that "disable all USB devices" case?

@MadYeti1984
Copy link

I just got around to testing my JetKVM. I've tested on 2 Windows 11 machines (latest updates). I cannot get the USB to register as connected on any USB ports on either machine. I made sure to update the JetKVM software first. Tried power cycling both PCs and JetKVM in different order, and still nothing. So, as of now can't use the KM rendering device unusable.

@IDisposable
Copy link
Contributor Author

IDisposable commented Jan 16, 2026 via email

@MadYeti1984
Copy link

MadYeti1984 commented Jan 17, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USB not detected if not present at startup

3 participants