Skip to content

Commit ed3403d

Browse files
authored
[Python] Avoid InvalidStateError on cancel (project-chip#35380)
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.
1 parent 83ae237 commit ed3403d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/controller/python/chip/ChipDeviceCtrl.py

+2
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,8 @@ def __init__(self, loop, future: asyncio.Future):
10621062
self._future = future
10631063

10641064
def _deviceAvailable(self):
1065+
if self._future.cancelled():
1066+
return
10651067
if self._returnDevice.value is not None:
10661068
self._future.set_result(self._returnDevice)
10671069
else:

0 commit comments

Comments
 (0)