irakhlin / hassio-usbip-mounter

Apache License 2.0
9 stars 14 forks source link

Device disconnected, reconnection impossible #9

Open Aaroneisele55 opened 2 months ago

Aaroneisele55 commented 2 months ago

Hello, I use this add-on to connect a Warema Stick from a RPi 3 (USBip server) to my main RPI4 where HA runs. On the first start of the system (e.g after piwer outage) the add-on starts correctly and the connection stays active until some network error stops the connection. However, instead of detaching the device cleanly (so it can be reattached after a restart of the add-on), the add-on gets into some kind of error state where the device isn't available on the HA host, but is also not detached, leading to a fault that can only be fixed by restarting the USBip server.

The Log outputs the following message when attempting to reconnect while in this state:

cont-init: info: /etc/cont-init.d/create_devices.sh exited 0
cont-init: info: running /etc/cont-init.d/load_modules.sh
cont-init: info: /etc/cont-init.d/load_modules.sh exited 0
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun usbip (no readiness notification)
services-up: info: copying legacy longrun usbipd (no readiness notification)
[19:09:14] INFO: Starting the USBIP Daemon
[19:09:14] INFO: Attaching usbip devices
usbipd: info: starting usbipd (usbip-utils 2.0)
usbipd: info: listening on 0.0.0.0:3240
usbipd: info: listening on :::3240
s6-rc: info: service legacy-services successfully started
++ mount -o remount -t sysfs sysfs /sys
++ /usr/sbin/usbip --debug attach -r 192.168.0.152 -b 1-1.2
usbip: debug: usbip.c:129:[run_command] running command: `attach'
usbip: error: tcp connect
[19:09:17] WARNING: usbip crashed, halting add-on
[19:09:17] INFO: usbip stopped, restarting...
s6-rc: info: service legacy-services: stopping
usbipd: info: shutting down usbipd
[19:09:17] INFO: usbipd stopped, restarting...

The add-on should normally detach devices when stopped, but it doesn't do this in this case...

How could I fix this?

Best regards Aaron Eisele

irakhlin commented 2 months ago

@Aaroneisele55 The most recent update I made was adding a "shutdown" script https://github.com/irakhlin/hassio-usbip-mounter/blob/main/rootfs/usr/bin/unmount_devices

If you shutdown the addon it will correctly detach from the server and thus the device can be reconnected. Unfortunately if there is some kind of network error or power outage and the script does not run the detach will not happen. From playing around with usbip outside of home assistant I have noticed that this issue will occur regardless. If the client does not correctly detach from the server the server ends up in a weird state. I will have to look into this to see if its something that can easily be solved.

Aaroneisele55 commented 1 month ago

I just thought about it and I think I have found a possible solution:

If the add--on crashes due to not being cleanly detached at some point, couldn't we just run the detachment script (from #6 ) when usbipd crahes, and then reattach the devices so the problematic state is resolved