You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
getDeviceList() does not update the list of devices properly #803
getDeviceList() will not show a device's new address if it is connected, removed, then reconnected.
Steps to Reproduce:
I tested this using "usbview.exe" to check the Device Address and a Typescript program that tries to find a Silicon Labs C8051 device with VID=0x10C4 and PID=0xEA61 every 3 seconds.
Connect the device and check the Device Address in "usbview.exe".
Launch the Typescript program. Observe that it can detect the device and reports the same Device Address.
Disconnect the device. Wait 2 seconds.
Reconnect the device. Observe that "usbview.exe" shows a different Device Address for the C8051, but the Typescript program continues to report the old Device Address.
Additional Information
Operating System: Windows 10
Runtime: Node v16.17.0
Node USB Version: usb@2.13.0
Typescript to reproduce:
import * as usb from 'usb';
async function main() {
let i = 0;
do {
await delay(3000);
const devices = usb.findByIds(<VENDOR_ID>, <PRODUCT_ID>);
console.log(`device run ${i}: `, devices);
i++;
} while (true);
}
function delay(ms: number) {
return new Promise( resolve => setTimeout(resolve, ms) );
}
main();
Thanks for raising this and the reproducer code.
I can confirm I see the same behaviour and the issue is apparent on windows 10. It looks like a race condition.
It doesn't seem to occur on macos, so seems to be OS specific.
I've had a play around with the code and even invalidating the internal cache doesn't fix the issue.
@thegecko After some discussion with tormodvolden, I've created an example project using C and the original libusb.dll: libusbTest.
I've included an example output from my program in the README. In the example, I started with my dongle connected, unplugged it after 3 loops, then plugged it back in at 7 loops. The device address updates correctly from 30 to 31.
If I comment out line 66 libusb_free_device_list(devs, 1); in my example, I get the same behavior as we see when we run GetDeviceList(): the device disappears when I disconnect it, and retains its old address when I reconnect it. This leads me to believe that libusb_free_device_list() is not running properly for some reason.
Not sure if this is related, but for us using node-usb in linux docker container with privileged access, getDeviceList(), then disconnect a device (getDeviceList the device is gone), then reconnect the device, the list will not have the reconnected device. The only way to make this work apparently is to restart the node instance. This is really not great for situation where device might be removed and reconnected.
Activity
thegecko commentedon Sep 28, 2024
Thanks for raising this and the reproducer code.
I can confirm I see the same behaviour and the issue is apparent on windows 10. It looks like a race condition.
It doesn't seem to occur on macos, so seems to be OS specific.
I've had a play around with the code and even invalidating the internal cache doesn't fix the issue.
Breaking it down to the fewest calls with libusb_get_device_list and printing the address returned with libusb_get_device_address still shows no change between disconnect/connect.
This leads me to believe its an issue with the
libusblibrary on windows and needs to be logged there.JonathanLeeIFX commentedon Sep 30, 2024
Thank you for your research and the additional information.
This is my first time opening an issue on GitHub, so I'm unsure how to proceed.
Can I open an issue in
libusband link it here?JonathanLeeIFX commentedon Oct 2, 2024
@thegecko After some discussion with tormodvolden, I've created an example project using C and the original libusb.dll: libusbTest.
I've included an example output from my program in the README. In the example, I started with my dongle connected, unplugged it after 3 loops, then plugged it back in at 7 loops. The device address updates correctly from
30to31.If I comment out line 66
libusb_free_device_list(devs, 1);in my example, I get the same behavior as we see when we runGetDeviceList(): the device disappears when I disconnect it, and retains its old address when I reconnect it. This leads me to believe thatlibusb_free_device_list()is not running properly for some reason.thegecko commentedon Oct 3, 2024
Thanks for looking in to this. I was hoping your research uncovered a need to call
libusb_free_device_list, but it appears we already do.I wonder if a reference to the device is being held somewhere...
goodwill commentedon Oct 20, 2025
Not sure if this is related, but for us using node-usb in linux docker container with privileged access, getDeviceList(), then disconnect a device (getDeviceList the device is gone), then reconnect the device, the list will not have the reconnected device. The only way to make this work apparently is to restart the node instance. This is really not great for situation where device might be removed and reconnected.