When the actor's websocket connection to the platform drops or times out (e.g., during actor migration or shutdown), the background task crashes with an unhandled asyncio.InvalidStateError.
This occurs because the exception handler inside PlatformEventManager._process_platform_messages attempts to call .set_result(False) on the self._connected_to_platform_websocket Future. However, because this Future was already resolved with True when the connection was initially established, calling .set_result() a second time raises an InvalidStateError which propagates unhandled and crashes the task.
Steps to reproduce the behavior:
- Run an Actor using the Python SDK.
- Trigger a platform websocket disconnect, such as a keepalive timeout (websockets.exceptions.ConnectionClosedError) or by migrating the Actor.
- Observe the unhandled InvalidStateError in the logs as the SDK attempts to set the Future result to False.
The SDK should handle the websocket error gracefully without raising a secondary InvalidStateError. The Future should be checked to see if it is already resolved before attempting to set a new result.
When the actor's websocket connection to the platform drops or times out (e.g., during actor migration or shutdown), the background task crashes with an unhandled asyncio.InvalidStateError.
This occurs because the exception handler inside
PlatformEventManager._process_platform_messagesattempts to call.set_result(False)on theself._connected_to_platform_websocketFuture. However, because this Future was already resolved with True when the connection was initially established, calling.set_result()a second time raises an InvalidStateError which propagates unhandled and crashes the task.Steps to reproduce the behavior:
The SDK should handle the websocket error gracefully without raising a secondary InvalidStateError. The Future should be checked to see if it is already resolved before attempting to set a new result.