Since transferIn is asynchronous, it's possible to have multiple async loops (see webUsbDevice.read()) to call transferIn, causing some packets to end up in the wrong read loop.
This manifests by a look expecting the first packet to have a header with a messageLength, but since the packet it receives is not really a first packet, but the middle of some other read, the read length is incorrect and causes an error when attempting to create a massively large array.
Resolution
Use p-queue to add an async queue with a concurrency of 1 to only allow one message and response to the device at a time.
Extra
This PR also simplifies some code around reading message length and concatenating packets.
Issue
Since
transferIn
is asynchronous, it's possible to have multiple async loops (seewebUsbDevice.read()
) to calltransferIn
, causing some packets to end up in the wrong read loop.This manifests by a look expecting the first packet to have a header with a
messageLength
, but since the packet it receives is not really a first packet, but the middle of some other read, the read length is incorrect and causes an error when attempting to create a massively large array.Resolution
Use
p-queue
to add an async queue with a concurrency of 1 to only allow one message and response to the device at a time.Extra
This PR also simplifies some code around reading message length and concatenating packets.