Skip to content
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

requestDevice not 'thread-safe' #40

Open
dsanders11 opened this issue Dec 20, 2018 · 0 comments
Open

requestDevice not 'thread-safe' #40

dsanders11 opened this issue Dec 20, 2018 · 0 comments

Comments

@dsanders11
Copy link
Contributor

Putting 'thread-safe' in quotes because really I'm referring to async code, but the idea is the same. Two different parts of code simultaneously accessing requestDevice will lead to a crash:

    at Device.require.usb.Device.close (node_modules/usb/usb.js:48:7)
    at node_modules/webusb/lib/adapter.js:411:28
    at Device.<anonymous> (node_modules/usb/usb.js:160:4)
    at Transfer.<anonymous> (node_modules/usb/usb.js:131:15)

As the error message suggests, I believe this is because while one request is ongoing the other code closes the device, leading to the crash.

I believe the offending code is in getCapabilities in adapter.ts. Off the top of my head, a possible solution may be to add a closeDevice method to dovetail with openDevice, and use reference counting to only close the device when it's safe to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants