labgrid-project / labgrid

Embedded systems control library for development, testing and installation
https://labgrid.readthedocs.io/
Other
343 stars 177 forks source link

util/agents/usb_hid_relay: fix concurrent access #1526

Closed jluebbe closed 1 month ago

jluebbe commented 1 month ago

Since c9fc5bfdb9da, it was no longer possible to use the same USB relay device from multiple labgrid processes, as the USB device was kept open and claimed.

To fix this, we use a context manager which first claims the USB interface (with retry while busy) and releases it after the transaction.

With this fix, multiple processes can toggle outputs in a busy loop without causing 'USBError(16, 'Resource busy')' failures.

Fixes: c9fc5bfdb9da ("labgrid/util/agents/usb_hid_relay: keep the USB device open")

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 0% with 32 lines in your changes missing coverage. Please review.

Project coverage is 56.7%. Comparing base (5e4ab58) to head (7ab6240). Report is 75 commits behind head on master.

Files with missing lines Patch % Lines
labgrid/util/agents/usb_hid_relay.py 0.0% 32 Missing :warning:

:exclamation: There is a different number of reports uploaded between BASE (5e4ab58) and HEAD (7ab6240). Click for more details.

HEAD has 1 upload less than BASE | Flag | BASE (5e4ab58) | HEAD (7ab6240) | |------|------|------| ||5|4|
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1526 +/- ## ======================================== - Coverage 61.8% 56.7% -5.2% ======================================== Files 166 168 +2 Lines 12305 13022 +717 ======================================== - Hits 7605 7384 -221 - Misses 4700 5638 +938 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.