Skip to content

getDeviceList() does not update the list of devices properly #803

Open

Description

@JonathanLeeIFX

Bug Description:

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.

  1. Connect the device and check the Device Address in "usbview.exe".
  2. Launch the Typescript program. Observe that it can detect the device and reports the same Device Address.
  3. Disconnect the device. Wait 2 seconds.
  4. 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();

Activity

  1. thegecko commented on Sep 28, 2024

    @thegecko
    Member

    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 libusb library on windows and needs to be logged there.

  2. JonathanLeeIFX commented on Sep 30, 2024

    @JonathanLeeIFX
    Author

    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 libusb and link it here?

  3. JonathanLeeIFX commented on Oct 2, 2024

    @JonathanLeeIFX
    Author

    @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.

  4. thegecko commented on Oct 3, 2024

    @thegecko
    Member

    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...

  5. goodwill commented on Oct 20, 2025

    @goodwill

    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.

  6. self-assigned this
    on Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions