-
-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to attach because of a problem in RegistryWatcher #80
Comments
When you run 'usbipd server', either from the command line or from a debugger, you must do so as administrator. My guess is you ran directly from visual studio, which would require you to run VS itself as root. |
Yes, when debugging I run Visual Studio as administrator. The same Exception in RegistryWatcher also occurs if I run usbipd.exe from the command line, but I'm running my recompiled version that logs any Exception within the try/finally clause of Server.ExecuteAsync(). When I run the release 1.1.1 version of usbipd from the command line, it fails silently, as shown below:
Does this output show that no Exception occurred? I'm not familiar with now anonymous methods handle an Exception without an Exception handler. If there's definitely no Exception occurring, then I'm clearly barking up the wrong tree with the RegistryWatcher issue - it must be a problem introduced when I recompiled the code -- so I'd need to debug with the release version instead. The "new connection from" and "connection closed" messages are from Server.ExecuteAsync(), but I guess other code gets invoked between those 2 logged messages, not just the RegistryWatcher code. I don't know if the "dbug: UsbIpServer.Server[0]" is a clue -- I can't figure out where that output comes from in the code. Nothing at all is written to the Event Viewer, so it would seem that no Warnings or Errors are being logged. Any suggestions on how I might better debug the problem? Thanks, Dan. |
- Incompatible with System.Management (due to COM dynamic typing) May solve #80
@gigamegawatts My best guess is: 1.1.1 uses so called "trimmed assemblies" in order to reduce the installation size. Converting to .NET 6 gave me a warning that System.Management (the component that actually does the registry watching) is in fact not compatible with trimming. Could you give the build artifact a try? It is at https://github.com/dorssel/usbipd-win/actions/runs/1453006711 |
Thanks for trying, but unfortunately that didn't fix the problem. Output from the attach command is the same as before:
If I run usbipd from the command line, output is almost the same as before:
There is no indication from Windows (in Device Manager) that it attempted to detach the USB device. No messages related to the program appear in the Event Viewer. The only difference from the 1.1.1 release is that "dbug: UsbIpServer.Server[0]" has changed to "dbug: UsbIpServer.Server[1000]". I don't know if that's significant. Do you know where that log statement comes from? I still can't find it. I tried running usbip list from the Linux side, and that fails with the same output from usbipd so whatever's going wrong isn't related to the process of detaching the USB device. Oddly, if I run uspibd in the debugger, the "usbip list" command still results in the same "Not Found" Exception in RegistryWatcher, though I don't think there's anything to watch for when handling a list command. Here's the output from the usbip (the "..." is just the rest of a very long list of device names from names.c):
Unless it would break other behavior in the program, would it be possible to add an Exception handler that logs any exception in the anonymous method in Server.ExecuteAsync(), such as:
I'm still not sure if an Exception occurs when I run your build - it might be something caused by my build. Thanks, Dan. |
Just so you know, the What puzzles me most is that you are able to do a listing on the host with It's best to first get EDIT: The registry watcher is not involved for listing devices. |
OK, I found the root cause of the problem. It's nothing to do with the usbipd-win code, so I'll close this issue. For reasons that I haven't figured out, on my PC the ManagementEventWatcher is looking in the 32-bit part of the Windows registry, not the 64-bit part. If I add the usbipd-win key to the 32-bit registry, the code works, but of course no registry change is ever detected so the detach command has no effect. That's actually not a showstopper for me, since I'll rarely need to switch the USB device back to Windows (I'm just working with embedded device development). I wrote a small program to just do the ManagementEventWatcher call, and can't find any workaround that can be implemented in code. The fix would presumably be somewhere in the WMI stack, but I couldn't find anything via Google. Perhaps I have the only PC in the world with this problem. I'll try reporting it to Microsoft, but I'm not optimistic. The only fix might be to do a clean install of Windows. If I run into similar issues with other software, I'll do just that. So, thanks for your help, and apologies for wasting your time with this bizarre problem. |
Problem was with user PC, not usbipd-win software. |
- Force 64-bit WMI - Adds logging on failed RegistryWatcher Maybe fixes #80
That's actually very interesting!
I made 2 changes in PR #89:
This means it should now work for you, although there is still something wrong with your 64-bit WMI provider. Maybe you should do some Could you test the build artifact at https://github.com/dorssel/usbipd-win/actions/runs/1455823723? |
Thanks, you found the root cause of the problem. The new code gave the same result, and still located the usbipd-win key if it was in the 32-bit part of the registry. But, your comment about the 64-bit WMI provider being the cause was absolutely correct. I finally thought to check the Task Manager to see what architecture WmiPrvSE.exe was running under, and there were actually 2 of them, one x86 and one x64. I killed the x86 one, and now usbipd-win works as expected, both attach and detach. (I'm still running the new build artifact - I can uninstall it and test with the 1.1.1 release if you don't intend to release the new code.) I haven't figured out what's starting the x86 one yet -- hopefully nothing malevolent. Thanks again for your help. |
And yet I again I learned something new (thanks!) It is perfectly normal that multiple such WmiPrvSE processes are running (I didn't know that, but just found out). They can run as different users (depending on the information queried: LOCAL SYSTEM, NETWORK SERVICE, etc.). And also at different bitness, depending on the bitness of the process querying. I also found a new flag: __RequiredArchitecture. It seems it works as follows: when a process requests information, the WMI service spawns a process to deal with it, unless such a process is already running. So, when I've updated #89 to now force 64-bit providers. It cannot hurt ( Thanks for staying in for the long haul on this one. Now I am ready to really close this one (unless you got some more...) |
- Force 64-bit WMI - Adds logging on failed RegistryWatcher Maybe fixes #80
The x86 copy of WmiPrvSE.exe that was running on my PC was under Username SYSTEM, so there were two different WmiPrvSE processes running under SYSTEM, one x86 and one x64. I'm not certain if this is a valid situation -- if so, then the WMI stack didn't handle it properly on my PC. The x86 version of WmiPrvSE.exe seems legit, not malware: it's located in a Windows\WinSxS subfolder. My suspicion was some MSI motherboard software service was launching it - it's a known troublemaker that caused unrelated problems when I did the Windows 11 upgrade. I uninstalled it and rebooted, and the x86 WmiPrvSE hasn't reappeared yet. Yes, you can consider the issue closed. The usbipd-win program is working great on my PC now. Thanks. |
I was having a problem attaching any device, and based on my debugging the problem seems to occur in RegistryWatcher when it tries to find the usbipd-win RootPath. I'm not familiar with the RegistryWatcher API, so I might be barking up the wrong tree, but let me explain...
I installed the 1.1.1 release of usbipd-win.
I made the specified changes to my WSL2 Ubuntu 20.04 distribution to enable usbip.
From an Administrative command prompt, usbipd wsl list works as expected, but usbipd wsl attach --busid=3-4 (or any other busid) fails with:
I tried stopping the service then running "usbipd server Logging:LogLevel:Default=Trace" from a command prompt. The request still fails, and the output from usbipd didn't specify the problem:
So, I downloaded the master branch of the project's code, and ran it in Visual Studio 2019. When I ran the attach request, an exception occurred in RegistryWatcher:
So, I put a breakpoint at line 29 of RegistryWatcher. The query it is running looks correct to me:
"SELECT * FROM RegistryTreeChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' AND RootPath='SOFTWARE\\\\usbipd-win'"
I checked the registry, and that key exists. But, when watcher.Start() runs, the "Not found" exception is thrown.
To see if the problem was specifically with the usbipd-win key, I changed the RootPath to a "known good" one:
"SELECT * FROM RegistryTreeChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' AND RootPath='SOFTWARE\\\\Microsoft'"
To my surprise, this not only prevented the "Not found" exception, but it actually allowed the program to continue successfully. It went into ConnectedClient.HandleRequestImportAsync() as expected, detached the device from Windows and attached it to Linux. The device showed up in Linux's lsusb output.
Although the code is using APIs that I've never worked with before, I assume that changing the RootPath will prevent detach requests from working, so this isn't a fix.
Do you have any ideas on why that RegistryWatcher query might fail on my PC, or what changes I might make to the query syntax to allow it to find the usbipd-win RootPath?
BTW, my PC isn't anything special: Win 11 Home upgraded from Win 10 Home. It's a relatively recent install of Win 10, from January of this year, and I've never messed around with the registry.
I exported the usbipd-win part of the registry. I can provide the full contents if you like, but the key names are:
Thanks,
Dan.
The text was updated successfully, but these errors were encountered: