usbipd detach not exiting properly #902
Replies: 6 comments 28 replies
-
Whenever a device is attached or detached, the USB port is reset to load a different driver. This essentially is an unplug/replug. For a brief moment, Windows doesn't see the device until the reset is complete and the device is enumerated again. When you run detach/attach in a batch script, then the attach is "too quick". This results in:
You probably need a "sleep" after every detach, to give Windows some time to re-detect the device. (Note: the way The stuck console is probably because you selected something in the console. That will freeze the console until you click again. It has nothing to do with |
Beta Was this translation helpful? Give feedback.
-
I put in a 1 second timeout after the detach command and the subsequent attach command worked. Really strange... |
Beta Was this translation helpful? Give feedback.
-
I saw you asked for a dedicated tools package for WSL. However, such tool packages already exist. They just happen to be distribution specific. For Ubuntu it is |
Beta Was this translation helpful? Give feedback.
-
I did a repair install and it made no difference. The detach command still hangs even if I execute it on windows.
Both Windows Linux are fully up to date. |
Beta Was this translation helpful? Give feedback.
-
I've tried all of the following:
In all cases, the console is hung until I click in the window in which I executed the command. By "hung" I mean that I cannot enter another command or up-arrow to another command. This is the same whether the command is executed natively in a Windows Command Prompt window or in WSL2 in a bash window. |
Beta Was this translation helpful? Give feedback.
-
Below is the output from executing the following command line:
In this case, the USB device was already detached before I executed the command:
In this case, the USB device was attached before I executed the command:
You can see that even though the detach command reported a clean exit, it did not complete cleanly because the device wasn't available to attach. If the device was already attached, it would have reported a different message. I can understand if my system was the only one with this problem, my system would be suspect. However, my system isn't the only one with this problem. If you want to take a look at my system, we can use TeamViewer. (I'm located in UTC-7.) |
Beta Was this translation helpful? Give feedback.
-
I'm using usbipd-win with WSL2 and Ubuntu 22.04 on a desktop computer running Windows 10 22H2. They are all up-to-date.
My usecase for usbipd-win requires the USB device to be attached before a service in default.target starts. I'm trying to write a systemd service to attach the device. I've never done this before, but it seems simple enough. I need the service to support start, stop and restart.
UPDATE: Since I wrote this post, I understand that systemctl restarts a service by issuing stop and start and there is not a restart. Regardless, that doesn't change that the detach command appears to not be exiting properly.
I wrote a bash script that takes one argument which can be start, stop or restart.
The output from the script with the restart argument is the following:
usbipd: error: There is no device with busid '4-4'.
(busid 4-4 is the actual busid of the particular device I'm testing with.)
In order to see if the problem was being caused by running the windows commands from within the WSL2 VM, I tested the commands on windows and found that the same thing happens, so I think there is a problem specifically with the usbipd detach command.
Here is are the commands to replicate the problem in batch file:
usbipd attach --wsl --busid=4-4
usbipd detach --busid=4-4
usbipd attach --wsl --busid=4-4
Here is the output:
`C:\WINDOWS\system32>usbipd attach --wsl --busid=4-4
usbipd: info: Using WSL distribution 'Ubuntu-22.04' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Using IP address 172.22.192.1 to reach the host.
C:\WINDOWS\system32>usbipd detach --busid=4-4
C:\WINDOWS\system32>usbipd attach --wsl --busid=4-4
usbipd: error: There is no device with busid '4-4'.`
If I run a stand-alone usbipd detach command, it displays a windows command prompt, but it doesn't output an info message like usbipd attach and the command prompt isn't working properly. For example, I can't up or down arrow to rerun a command, even if I enter CTRL-C to force an exit. I found that by clicking the mouse in the window, it seems to exit, after which I can up or down arrow the command line.
After the usbipd detach command exits, if I run it again, I get the following output:
C:\WINDOWS\system32>usbipd detach --busid=4-4 usbipd: info: Device with busid '4-4' was already not attached.
Based on these findings, the only conclusion I can reach is that the usbipd detach command doesn't exit properly.
Is this a known problem? Is there a work-around?
Beta Was this translation helpful? Give feedback.
All reactions