Fixing an issue where valid HID responses are discarded #334
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have observed that occasionally VIA will not complete the Authorize Device process. Also, for a larger keyboards especially, the Test Matrix feature will consistently lock up and stop responding after a few seconds (whereas disabling "Test Matrix" continues to work just fine). After a bit of in-browser debugging, I learned that the call to
fastForwardGlobalBufferdiscards HID responses received prior to wheneverreadwas called.It turns out that due to the use of
async/await, there can be some delay between thewritefunction call and thereadfunction call. What was happening was that the device had already responded quickly between the time whenwritewas called and the time whenreadwas called. Whenever the device responds beforereadis called, that response is then erroneously discarded by the fast forward function. VIA is then stuck waiting for a response that will never arrive (because it already did arrive, and was discarded), causing Test Matrix to stop working, and/or causing the authorization process to halt.This PR makes it so that
fastForwardGlobalBufferonly discards messages prior to the previous call towriteinstead of discarding messages prior to whenreadis called.Note that these changes were tested by editing the code through browser developer tools by enabling overrides and thus running it in-browser. The changes in this PR match what I did in-browser and it looks correct to me, but I haven't actually run/tested the committed changes as-is simply because I haven't set up an environment to run/host VIA independently. That being said, I can confirm these when I made these same changes in-browser, they worked and actually fixed the issues I was experiencing.
Edit: It should also be noted that the problems I mentioned would only show up when the CPU load was higher (i.e. lots of tabs open in the browser, or on older computers).