Skip to content

Commit

Permalink
fix(robot-server): dont let /instruments block
Browse files Browse the repository at this point in the history
It calls cache_instruments and that can block because it takes the
motion lock, but we really don't want that. We don't mind if
cache_instruments doesn't get called on the flex because it's sort of a
secondary functionality, so just bail early in this case.

Closes EXEC-298
  • Loading branch information
sfoster1 committed Mar 7, 2024
1 parent d6d9416 commit e87e572
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion api/src/opentrons/hardware_control/ot3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,16 @@ def get_all_attached_instr(self) -> Dict[OT3Mount, Optional[InstrumentDict]]:

# TODO (spp, 2023-01-31): add unit tests
async def cache_instruments(
self, require: Optional[Dict[top_types.Mount, PipetteName]] = None
self,
require: Optional[Dict[top_types.Mount, PipetteName]] = None,
skip_if_would_block: bool = False,
) -> None:
"""
Scan the attached instruments, take necessary configuration actions,
and set up hardware controller internal state if necessary.
"""
if skip_if_would_block and self._motion_lock.locked():
return
async with self._motion_lock:
skip_configure = await self._cache_instruments(require)
if not skip_configure or not self._configured_since_update:
Expand Down
2 changes: 1 addition & 1 deletion robot-server/robot_server/instruments/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async def _get_attached_instruments_ot3(
hardware: OT3HardwareControlAPI,
) -> PydanticResponse[SimpleMultiBody[AttachedItem]]:
# OT3
await hardware.cache_instruments()
await hardware.cache_instruments(skip_if_would_block=True)
response_data = await _get_instrument_data(hardware)
return await PydanticResponse.create(
content=SimpleMultiBody.construct(
Expand Down

0 comments on commit e87e572

Please sign in to comment.