Skip to content

Commit

Permalink
[Python] Avoid InvalidStateError on cancel (#35380)
Browse files Browse the repository at this point in the history
When the co-routine GetConnectedDevice() gets cancelled, the wait_for
call will cancel the future we are waiting for. However, the SDK still
calls the _DeviceAvailableCallback with an error (CHIP Error 0x00000074:
The operation has been cancelled). However, we can't set the future
result at this point as the co-routine is already cancelled.

Simply check the future state before setting the result.
  • Loading branch information
agners authored Sep 4, 2024
1 parent 83ae237 commit ed3403d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,8 @@ def __init__(self, loop, future: asyncio.Future):
self._future = future

def _deviceAvailable(self):
if self._future.cancelled():
return
if self._returnDevice.value is not None:
self._future.set_result(self._returnDevice)
else:
Expand Down

0 comments on commit ed3403d

Please sign in to comment.