WICG / webusb

Connecting hardware to the web.
https://wicg.github.io/webusb/
Other
1.3k stars 126 forks source link

the program stoped when I send data to device. Use transferOut() on linux #200

Closed qcscofield closed 2 years ago

qcscofield commented 2 years ago

async function(ep, data) { console.log('before') let r = await this.device.transferOut(ep, data); console.log('after') return r above code running. 'after' string can't output. device.transferOut(ep, data); dont have return. the windows works good but linux.

reillyeon commented 2 years ago

This is likely a Chromium issue or a device issue. Please file a bug report on crbug.com. You can use Wireshark to capture a packet trace which will show the submission and completion (or lack there of) of the OUT transfer request on the endpoint.

hires commented 2 years ago

I have tested this on Linux and Mac in both Chromium and Opera (Linux) and Chrome (Mac) and the results are identical. I can send the first transferOut() request but any subsequent ones block indefinitely until I turn off or unplug the USB device. Please help!

reillyeon commented 2 years ago

@hires Have you tried collecting a USB trace with Wireshark on Linux?

hires commented 2 years ago

@reillyeon Thanks for the quick reply! Yes I have a hardware USB analyzer connected to my device.

I think I figured it out although it was strange... the particular device needed a control transfer sent before it would accept data on the bulk EP. The symptom was the second transfer to the bulk EP would hang until the device was turned off or unplugged. (seemed suspicious!)

I think the device malfunctioned and made whatever driver/system call is behind transferOut() hang indefinitely even though the first transfer was complete on the bus. Very weird! Anyway hopefully this will help someone else in the future!

reillyeon commented 2 years ago

That is odd because the transfer should eventually complete once the device stops responding to the host with a NAK. If you use Wireshark instead of the hardware analyzer does it show the URB completing from Linux's perspective? It would be a Chromium bug if Linux considered the URB complete but the browser didn't resolve the Promise.

hires commented 2 years ago

The Wireshark trace seems to show that the second bulk transfer was not completed. Indeed the hardware trace shows the device sending NAK to subsequent OUT packets. It feels strange that there is no timeout. It was ultimately my fault but this behaviour led me down the wrong path for quite a while. :)

Thanks for your help.